2016-11-26 3 views
0

Я новичок в android. Я хотел бы иметь tabhost с включенными, но вкладки не будут отображаться. Это 2 включает в себя простые или базовые логические входы, такие как текстовые поля и кнопки. Все коды находятся в этом основном действии, например, сохраняя материал db и другие.TabHost и включают

Вот код.

<TabHost 
 
     xmlns:android="http://schemas.android.com/apk/res/android" 
 
     android:id="@+id/tabHost" 
 
     android:layout_width="fill_parent" 
 
     android:layout_height="match_parent"> 
 
     <LinearLayout 
 
      android:id="@+id/line" 
 
      android:layout_width="fill_parent" 
 
      android:layout_height="match_parent" 
 
      android:orientation="vertical"> 
 
      <TabWidget 
 
       android:id="@android:id/tabs" 
 
       android:layout_width="fill_parent" 
 
       android:layout_height="wrap_content" 
 
       android:layout_weight="0"></TabWidget> 
 
      <FrameLayout 
 
       android:id="@android:id/tabcontent" 
 
       android:layout_width="fill_parent" 
 
       android:layout_height="0dip" 
 
       android:layout_weight="1"> 
 
       <include android:id="@+id/layout1" 
 
        layout="@layout/layout_add_details" 
 
        android:layout_width="match_parent" 
 
        android:layout_height="match_parent"></include> 
 
       <include android:id="@+id/layout2" 
 
        layout="@layout/layout_add_number" 
 
        android:layout_width="match_parent" 
 
        android:layout_height="match_parent"></include> 
 
      </FrameLayout> 
 
     </LinearLayout> 
 
    </TabHost>

Вот как я настроить tabhost.

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
     TabHost tab = (TabHost) findViewById(R.id.tabHost); 
     tab.setup(); 

     TabHost.TabSpec spec1 = tab.newTabSpec("TAB 1"); 
     spec1.setIndicator("TAB 1"); 
     spec1.setContent(R.id.layout1); 
     tab.addTab(spec1); 

     TabHost.TabSpec spec2 = tab.newTabSpec("TAB 2"); 
     spec2.setIndicator("TAB 2"); 
     spec2.setContent(R.id.layout2); 
     tab.addTab(spec2); 
} 

Заранее благодарен!

ответ

0

thiis - как я решил мой. У меня есть Tabhost с тремя вкладками внутри. На втором у меня есть фрагмент карты Google, а на двух других я имею простые текстовые поля. Только третья вкладка добавляется с помощью включают установки

Так вот как основной макет выглядит

<TabHost 
     android:id="@+id/tab_host_main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

      <TabWidget 
       android:id="@android:id/tabs" 
       android:layout_width="match_parent" 
       android:layout_height="40dp" /> 

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

       <LinearLayout 
        android:id="@+id/tab1" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical"> 

        <TextView 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:text="tab one"/> 

       </LinearLayout> 

       <LinearLayout 
        android:id="@+id/map_tab" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical"> 

        <fragment 
         android:id="@+id/map" 
         android:name="com.google.android.gms.maps.SupportMapFragment" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" 
         tools:context=".MapsActivity" /> 
       </LinearLayout> 

       <FrameLayout 
        android:id="@+id/tab3" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="vertical"> 

        <include 
         layout="@layout/tab_three_content" 
         android:layout_width="match_parent" 
         android:layout_height="match_parent" /> 


       </FrameLayout> 
      </FrameLayout> 
     </LinearLayout> 
    </TabHost> 

И это вкладка три макета, который я создал отдельно и вставляется в предыдущий с использованием include.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Hello from tab three"/> 

</LinearLayout> 
Смежные вопросы