2012-09-18 62 views
0

我需要一点帮助Android设计的选项卡。正如您在下面的图片中看到的那样,标签看起来非常难看且非常宽泛。我怎么能让这看起来更瘦,因为我只想在这里没有很多empy空间的文本。Android Tabs设计问题

enter image description here

我的第二个问题是,这显示图像下面,我加载其他活动这个第一个选项卡上的数据,但它看起来很畸形,你可以下面的图片上看到的。在其他活动中,我有ScrolView。

enter image description here

回答

0

通过这种方法,你可以创建自定义选项卡

创建一个布局来表示TabIndicator

这是tab_indicator.xml

<?xml version="1.0" encoding="utf-8"?> 

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/tv_tabTitle" 
       android:layout_width="fill_parent" 
       android:layout_height="35dp" 
       android:background="@drawable/bg_tab_indicator" 
       android:gravity="center" 
       android:textSize="15sp" 
       android:textColor="@drawable/tv_tab_indicator_title" 
       android:text="Tab title" 
       /> 

这是bg_tab_indicator.xml绘制

<?xml version="1.0" encoding="utf-8"?> 

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 

    <!-- Unselected tab --> 
    <item android:state_focused="false" 
      android:state_selected="false" 
      android:state_pressed="false" 
      android:drawable="@drawable/bg_tab_indicator_unselected"/> 

    <!-- Selected tab --> 
    <item android:state_focused="false" 
      android:state_selected="true" 
      android:state_pressed="false" 
      android:drawable="@drawable/bg_tab_indicator_selected"/> 

    <!-- Pressed tab --> 
    <item android:state_pressed="true" 
      android:drawable="@drawable/bg_tab_indicator_pressed"/> 

    <!-- Selected tab using dial pad --> 
    <item android:state_pressed="false" 
      android:state_focused="true" 
      android:state_selected="true" 
      android:drawable="@drawable/bg_tab_indicator_selected"/> 

</selector> 

现在你TabActivity

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.tab_activity); 
    //if you are not using TabActivity then use findViewById(id) to find tabHost 
    final TabHost tabHost = getTabHost(); 
    tabHost.setup(); 
    //if you are not using TabActivity then use findViewById(id) to find tabWidget 
    TabWidget tabWidget = getTabWidget(); 
    tabWidget.setDividerDrawable(R.drawable.divider_tab); 
    addTab("Tab1", tabHost, R.id.tab1); 
    addTab("Tab2", tabHost, R.id.tab2); 
    addTab("Tab3", tabHost, R.id.tab3); 
} 

这是addTab方法

private void addTab(String label, TabHost tabHost, int content){ 
    TabHost.TabSpec tabSpec = tabHost.newTabSpec(label) 
      .setIndicator(indicatorView(label)) 
      .setContent(content); 
    tabHost.addTab(tabSpec); 
} 

这种方法产生indicatorView

private View indicatorView(String label){ 
    View view = layoutInflater.inflate(R.layout.tab_indicator, null); 
    TextView textView = (TextView) view; 
    textView.setText(label); 
    return view; 
} 

希望这将帮助你