2015-12-18 3 views
0

Я искал пример, но когда я добавил в свой xml, он не сработал. Кто-то может мне помочь.Не удалось выровнять мой табуст внизу

Это мой XML tabhost

<?xml version="1.0" encoding="utf-8"?> 
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/tabHost"> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:padding="5dp" 
     android:gravity="bottom"> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"/> 

     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="5dp" 
      android:layout_gravity="bottom"/> 

    </LinearLayout> 
</TabHost> 

Это индикатор вкладки с точки зрения ImageView и текста.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="45dp" 
    android:layout_weight="1" 
    android:gravity="center"> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingTop="10dp" 
     android:id="@+id/img_tabhost" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/img_tabhost" 
     android:textSize="15sp" 
     android:id="@+id/tv_tabhost" /> 

</RelativeLayout> 

и это класс я работал

private TabHost tabHost; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    tabHost = getTabHost(); 

    String tabName = ""; 
    addTab(tabName, R.drawable.ic_home); 
    addTab(tabName, R.drawable.ic_search); 
    addTab(tabName, R.drawable.ic_notification); 
    addTab(tabName, R.drawable.ic_profile); 

} 

private void addTab(String label, int drawableId){ 
    Intent intent = new Intent(); 

    switch (drawableId){ 
     case R.drawable.ic_home: 
      //label = "Home"; 
      intent = new Intent(this, Map.class); 
      break; 
     case R.drawable.ic_search: 
      //label = "Search"; 
      intent = new Intent(this, Search.class); 
      break; 
     case R.drawable.ic_notification: 
      //label = "Notifications"; 
      intent = new Intent(this, Notifications.class); 
      break; 
     case R.drawable.ic_profile: 
      //label = "Profile"; 
      intent = new Intent(this, Profile.class); 
      break; 

    } 

     // Create the tab hosts 
     TabHost.TabSpec spec = this.getTabHost().newTabSpec(label); 

     View tabIndicator = LayoutInflater.from(this).inflate(
       R.layout.tab_indicator, getTabWidget(), false); 
     TextView title = (TextView) tabIndicator.findViewById(R.id.tv_tabhost); 
     title.setText(label); 
     ImageView icon = (ImageView) tabIndicator.findViewById(R.id.img_tabhost); 
     icon.setImageResource(drawableId); 

     spec.setContent(intent); 
     spec.setIndicator(tabIndicator); 
     tabHost.addTab(spec); 

} 

Может кто-нибудь помочь мне установить мой tabhost в нижней части.

android:layout_alignParentBottom:true  

не работают

ответ

0

Для того, чтобы установить android:layout_alignParentBottom атрибут, вы должны использовать RelativeLayout вместо LinearLayout. Таким образом, ваш xml должен выглядеть так:

<TabHost xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/tabHost"> 

    <RelativeLayout 
     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" 
      android:layout_marginBottom="5dp" 
      android:layout_alignParentBottom="true"/> <!-- now you can use it --> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"/> 
    </RelativeLayout> 
</TabHost>