Why is the drawable overlapping the text in my tabview

扶醉桌前 提交于 2019-12-13 21:46:00

问题


Why does the tab text overlap the drawable in the tab? Is there a way to prevent this? Is the drawable always centered? What's the point of being able to add text as well as a drawable to the indicator if it gives this output.

xml

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"    
    android:id="@android:id/tabhost"    
    android:layout_width="fill_parent"    
    android:layout_height="fill_parent">    
    <LinearLayout        
        android:orientation="vertical"        
        android:layout_width="fill_parent"        
        android:layout_height="fill_parent"        
        android:padding="5dp">  
        <TabWidget            
            android:id="@android:id/tabs"            
            android:layout_width="fill_parent"            
            android:layout_height="wrap_content"/>        
        <FrameLayout            
            android:id="@android:id/tabcontent"            
            android:layout_width="fill_parent"            
            android:layout_height="fill_parent"            
            android:padding="5dp" />  
</LinearLayout>
</TabHost>

java


 host.addTab(host.newTabSpec("_tab2") 
                .setIndicator("Authors",res.getDrawable(android.R.drawable.ic_menu_mapmode))  
                .setContent(new Intent(this, AuthorList.class)));

Can anyone else help? I've tried everythin I can think of and it looks like this both in my phone and my emulator. I've used tabs before and it didn't do this.


回答1:


Refer to the "Size and positioning" section in: http://developer.android.com/guide/practices/ui_guidelines/icon_design_tab.html

Most likely you have icons with dimensions that are under the incorrect resolution level (ldpi, mdpi, hdpi). This happened to me when my icons were 30x30 under ldpi. I resized them to 28x28 and put them under mdpi as the documentation suggests.

In addition, the documentation recommends against using colors, especially for unselected tabs as you have done. Making them grayscale and using the gray/white paradigm makes it look a lot cleaner with that theme.




回答2:


in each instance that I've used this, Its worked for me, but for you the only thing I see that may help, is try upping the padding just a tiny bit, check out if it works better with more padding to the word



来源:https://stackoverflow.com/questions/3982461/why-is-the-drawable-overlapping-the-text-in-my-tabview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!