2012-09-18 67 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; 
} 

希望這將幫助你