Android - TabHost пуст в некоторых действиях и хорошо в других - PullRequest
0 голосов
/ 24 января 2012

Я использую tabHost в определенных макетах в моем приложении, и они хорошо работают в определенных действиях, но в других отображаются пустыми. Я перепробовал несколько настроек, но по какой-то причине tabhost оказался пустым в одном действии, но он отлично работает в других.

Есть что-то, чего мне не хватает .... вот мой код, который я использую для отображения моей вкладкиHost:

dialog2.setContentView(R.layout.maintabmenu);


    final TabHost tabs = (TabHost)dialog2.findViewById(R.id.my_tabhost);
    tabs.setup();
    tabs.setCurrentTab(0);

    TabSpec tspec11 = tabs.newTabSpec("New Tab");
    tspec11.setIndicator("User");

    tspec11.setContent(R.id.ScrollView01);
    tabs.addTab(tspec11);

    TabSpec tspec3 = tabs.newTabSpec("New Tab");
    tspec3.setIndicator("My options");
    tspec3.setContent(R.id.ScrollView03);
    tabs.addTab(tspec3);
    ///the reset of set up omitted 

и затем xml:

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

    <LinearLayout
             android:orientation="vertical"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             android:padding="5dp">
       <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
       <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="5dp">

       <ScrollView android:id="@+id/ScrollView01"
           android:layout_width="match_parent"
                   android:layout_height="match_parent">

            <RelativeLayout 
                   android:layout_width="match_parent"
                   android:layout_height="match_parent"
                   android:background="@drawable/bggreydotted"
                   android:orientation="vertical" >
               <TextView
                     android:id="@+id/usersname"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:layout_alignParentTop="true"
                     android:layout_centerHorizontal="true"
                     android:text="User Info" />
               <ImageView
                     android:id="@+id/profileimage2"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:layout_centerHorizontal="true"
                     android:layout_centerInParent="true"
                     android:layout_centerVertical="true"
                     android:src="@drawable/favicon_yellow_g_metal_bg2" />
               <ImageButton
                     android:id="@+id/drawMark"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:layout_alignParentRight="true"
                     android:layout_below="@+id/createMarks"
                     android:background="@null"       
                     android:src="@drawable/graffitbuttondrawmark" />
              <ImageButton
                     android:id="@+id/zmLevel"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:layout_alignParentLeft="true"
                     android:layout_below="@+id/search"
                     android:background="@null"        
                     android:src="@drawable/graffitbuttonzoomlevel" />
              <ImageButton
                     android:id="@+id/license"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:layout_alignParentRight="true" 
                     android:layout_below="@+id/mypreferences"
                     android:background="@null"
                     android:src="@drawable/graffitbuttonlicense" />
              <ImageButton
                     android:id="@+id/mapView"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:layout_below="@+id/zmLevel"
                     android:layout_alignParentLeft="true"
                     android:background="@null" 
                     android:src="@drawable/graffitbuttonmapview" />
              <ImageButton
                     android:id="@+id/mypreferences"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:layout_alignParentRight="true"
                     android:layout_below="@+id/drawMark"
                     android:background="@null"        
                     android:src="@drawable/graffitbuttonuserpreference" />
              <ImageButton
                     android:id="@+id/search"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:layout_alignParentLeft="true"
                     android:layout_below="@+id/marksNearMe"
                     android:background="@null"        
                     android:src="@drawable/graffitbuttonmarksearch" />
              <ImageButton
                     android:id="@+id/createMarks"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:background="@null"
                     android:layout_alignParentTop="true"
                     android:layout_alignParentRight="true"
                     android:src="@drawable/graffitbuttonuploadphoto" />
              <ImageButton
                     android:id="@+id/marksNearMe"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:background="@null"
                     android:layout_alignParentLeft="true"
                     android:layout_alignParentTop="true"
                     android:src="@drawable/graffitbuttonmarksnearme" />
           </RelativeLayout>
       </ScrollView>                
       <ScrollView android:id="@+id/ScrollView03"
            android:layout_width="match_parent"
                    android:layout_height="match_parent">              
           <RelativeLayout 
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/bggreydotted"
                    android:orientation="vertical" >
              <TextView
                       android:id="@+id/userinfo"
                       android:layout_width="wrap_content"
                       android:layout_height="wrap_content"
                       android:layout_centerHorizontal="true"
                       android:text="USER INFO" />
              <ImageView
                       android:id="@+id/profileimage"
                       android:layout_width="wrap_content"
                       android:layout_height="wrap_content"
                       android:layout_centerHorizontal="true"
                       android:layout_centerInParent="true"
                       android:layout_centerVertical="true"
                       android:src="@drawable/favicon_yellow_g_metal_bg2" />
              <ImageButton
                       android:id="@+id/sky"
                       android:layout_width="wrap_content"
                       android:layout_height="wrap_content"
                       android:layout_alignParentLeft="true" 
                       android:layout_below="@+id/mymarks"
                       android:background="@null"
                       android:src="@drawable/graffitbuttonsky" />
             <ImageButton
                       android:id="@+id/myclicks"
                       android:layout_width="wrap_content"
                       android:layout_height="wrap_content"
                       android:layout_alignParentLeft="true"
                       android:layout_alignParentTop="true"
                       android:background="@null"
                       android:src="@drawable/graffitbuttonmyclicks" />
             <ImageButton
                       android:id="@+id/mygallery"
                       android:layout_width="wrap_content"
                       android:layout_height="wrap_content"
               android:layout_alignParentLeft="true"
               android:layout_below="@+id/myclicks"
                       android:background="@null"
                       android:src="@drawable/graffitbuttonmygallery" /> 
            <ImageButton
                       android:id="@+id/mymarks"
                       android:layout_width="wrap_content"
                       android:layout_height="wrap_content"
                       android:layout_alignParentLeft="true"
                       android:layout_below="@+id/mygallery"
                       android:background="@null"
                       android:src="@drawable/graffitbuttonmymarks" />
            <ImageButton
                       android:id="@+id/help"
                       android:layout_width="wrap_content"
                       android:layout_height="wrap_content"
                       android:layout_alignParentRight="true" 
                       android:layout_below="@+id/createuser"
                       android:background="@null"
                       android:src="@drawable/graffitbuttonhelp" />
            <ImageButton
                       android:id="@+id/createuser"
                       android:layout_width="wrap_content"
                       android:layout_height="wrap_content"
                       android:layout_alignParentRight="true" 
                       android:layout_below="@+id/logout"
                       android:background="@null"
                       android:src="@drawable/graffitbuttoncreateuser" />
            <ImageButton
                       android:id="@+id/login"
                       android:layout_width="wrap_content"
                       android:layout_height="wrap_content"
                       android:layout_alignParentTop="true"
                       android:layout_alignParentRight="true"
                       android:background="@null"
                       android:src="@drawable/graffitbuttonlogin3" />
            <ImageButton
                       android:id="@+id/logout"
                       android:layout_width="wrap_content"
                       android:layout_height="wrap_content"
                       android:layout_alignParentRight="true"
                       android:layout_below="@+id/login"
                       android:background="@null"
                       android:src="@drawable/graffitbuttonlogout" />
         </RelativeLayout>
      </ScrollView>                 
   </FrameLayout>
 </LinearLayout>    
</TabHost>

1 Ответ

0 голосов
/ 25 января 2012
I ended up having to put my layout like so:


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


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

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
   <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">



              <RelativeLayout 
                  android:id="@+id/rlone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bggreydotted"
android:orientation="vertical" >

<TextView
    android:id="@+id/usersname"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:text="User Info" />

<ImageView
    android:id="@+id/profileimage2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerInParent="true"
    android:layout_centerVertical="true"
    android:src="@drawable/favicon_yellow_g_metal_bg2" />


<ImageButton
    android:id="@+id/drawMark"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/createMarks"
    android:background="@null"

    android:src="@drawable/graffitbuttondrawmark" />

<ImageButton
    android:id="@+id/zmLevel"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
   android:layout_alignParentLeft="true"
   android:layout_below="@+id/search"
    android:background="@null"

    android:src="@drawable/graffitbuttonzoomlevel" />

<ImageButton
    android:id="@+id/license"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true" 
    android:layout_below="@+id/mypreferences"
    android:background="@null"
    android:src="@drawable/graffitbuttonlicense" />

<ImageButton
    android:id="@+id/mapView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/zmLevel"
    android:layout_alignParentLeft="true"
    android:background="@null" 
    android:src="@drawable/graffitbuttonmapview" />

<ImageButton
    android:id="@+id/mypreferences"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/drawMark"
    android:background="@null"

    android:src="@drawable/graffitbuttonuserpreference" />

<ImageButton
    android:id="@+id/search"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/marksNearMe"
    android:background="@null"

    android:src="@drawable/graffitbuttonmarksearch" />

<ImageButton
    android:id="@+id/createMarks"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@null"
     android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:src="@drawable/graffitbuttonuploadphoto" />

<ImageButton
    android:id="@+id/marksNearMe"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@null"
     android:layout_alignParentLeft="true"
     android:layout_alignParentTop="true"
    android:src="@drawable/graffitbuttonmarksnearme" />

</RelativeLayout>


               <RelativeLayout 
                   android:id="@+id/rltwo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bggreydotted"
android:orientation="vertical" >


<TextView
    android:id="@+id/userinfo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:text="USER INFO" />

<ImageView
    android:id="@+id/profileimage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerInParent="true"
    android:layout_centerVertical="true"
    android:src="@drawable/favicon_yellow_g_metal_bg2" />

<ImageButton
    android:id="@+id/sky"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/mymarks"
    android:background="@null"
    android:src="@drawable/graffitbuttonsky" />

<ImageButton
    android:id="@+id/myclicks"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:background="@null"
    android:src="@drawable/graffitbuttonmyclicks" />

<ImageButton
    android:id="@+id/mygallery"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/myclicks"
    android:background="@null"
    android:src="@drawable/graffitbuttonmygallery" />

<ImageButton
    android:id="@+id/mymarks"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/mygallery"
    android:background="@null"
    android:src="@drawable/graffitbuttonmymarks" />

<ImageButton
    android:id="@+id/help"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true" 
    android:layout_below="@+id/createuser"
    android:background="@null"
    android:src="@drawable/graffitbuttonhelp" />

<ImageButton
    android:id="@+id/createuser"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true" 
    android:layout_below="@+id/logout"
    android:background="@null"
    android:src="@drawable/graffitbuttoncreateuser" />

<ImageButton
    android:id="@+id/login"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:background="@null"
    android:src="@drawable/graffitbuttonlogin3" />

<ImageButton
    android:id="@+id/logout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/login"
    android:background="@null"
    android:src="@drawable/graffitbuttonlogout" />

</RelativeLayout>



    </FrameLayout>
</LinearLayout>
...