2011-11-15 90 views
0

enter image description here佈局顯示問題使用Android TabHost

我正在使用android tabhost的應用程序。我面臨使用它的問題,因爲我的活動佈局在標籤下顯示不正確。活動的佈局只顯示在仿真器屏幕的上半部分,下半部分保持黑色,而當我在設計視圖中看到它的xml時,它將描述所需的設計。

XML如下添加myscreen.xml:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@color/gray" 
android:orientation="vertical"> 
<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_gravity="center_vertical" 
    android:orientation="vertical" 
    android:gravity="center"> 
    <ImageView 
     android:id="@+id/button_twitter" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/twitter_login_unpressed" /> 
    <ImageView 
     android:id="@+id/button_separator" 
     android:layout_width="wrap_content" 
     android:layout_height="30px" 
     android:background="@color/gray" /> 
    <ImageView 
     android:id="@+id/button_facebook" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/facebook_login_unpressed" /> 
</LinearLayout> 

及有關活動只包含的onCreate下面的代碼:

protected void onCreate(Bundle savedInstanceState) { 

    Log.e("Now", "onCreate"); 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.myscreen); 

}

我無法弄清楚HY選項卡下的整個佈局沒有正確顯示,和tabActivity只是有和意圖這種活動,沒有什麼複雜的在那裏...它包含以下代碼:

公共類InfoTabActivity擴展TabActivity {

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.infotablayout); 
    Resources res = getResources(); 
    TabHost tabHost = getTabHost(); 
    TabHost.TabSpec spec; 
    Intent intent; 

    intent = new Intent().setClass(this, myActivity.class); 
    spec = tabHost.newTabSpec("settings").setIndicator("", res.getDrawable(R.drawable.today_unpressed)).setContent(intent); 
    tabHost.addTab(spec); 



    tabHost.setCurrentTab(0); 
} 

}

可能是什麼問題?任何幫助表示讚賞。

infotablayout.xml包含此代碼:在

<?xml version="1.0" encoding="utf-8"?> 
    <TabHost 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/tabhost" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:padding="5dp"> 
     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="45px" /> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:padding="5dp" /> 
    </LinearLayout> 
</TabHost> 
+0

可以在此添加的快照? – Hiral

+0

你肯定..我補充說.... –

+0

和請發佈您的infotablayout.xml。 – Hiral

回答

1

問題是最有可能您infotablayout.xml - 在FrameLayout您使用TabContent最有可能具有屬性layout_height="wrap_content"。 (也許你可以發佈這個XML文件,所以我們可以看看)。

編輯

持有的LinearLayoutTabWidgetFrameLayout有其高度設置爲wrap_content這就是爲什麼你的佈局套。


小題外話,但你應該能夠在您的myscreen.xml文件減少到以下幾點:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@color/gray" 
android:orientation="vertical" 
android:layout_gravity="center_vertical" 
android:gravity="center"> 
    <ImageView 
     android:id="@+id/button_twitter" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/twitter_login_unpressed" 
     android:layout_marginBottom="15dp" /> 
    <ImageView 
     android:id="@+id/button_facebook" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/facebook_login_unpressed" 
     android:layout_marginTop="15dp" /> 
</LinearLayout> 
+0

@Kasper ....我的權利,但這只是看看事情如果我包括另一個線性佈局在那....我已經添加tablayout ...檢查出來。 .. !!!! –

+0

包含「TabWidget」和「FrameLayout」的'LinearLayout'將其高度設置爲'wrap_content',這就是佈局換行的原因。 – kaspermoerch

+0

就是這樣....謝謝Kasper ...它對我非常好.... .... –