2011-04-26 40 views
0

我在我的機器人應用此佈局文件:線性佈局內TabHost僅示出一個元件

<?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="fill_parent"> 
     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1"> 
      <TextView 
       android:id="@+id/textview1" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:text="this is a tab" /> 
      <TextView 
       android:id="@+id/textview2" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:text="this is another tab" /> 
      <LinearLayout 
       android:id="@+id/layoutSearch" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="vertical"> 
       <TextView 
        android:id="@+id/textview4" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:text="Search here" /> 
       <EditText 
        android:id="@+id/editSearch" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" /> 

      </LinearLayout> 
     </FrameLayout> 
     <TabWidget 
      android:id="@android:id/tabs" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="0"/> 
    </LinearLayout> 
</TabHost> 

我的問題是LinearLayout android:id="@+id/layoutSearch"僅示出它包含的元素中的一個(文本視圖,在上面的代碼)如果我刪除了textview,它會顯示EditText。

我如何讓它顯示兩個(及以上)的元素?

+0

我知道這可能看起來像我複製一個iPhone應用程序,但IMO這使得它更容易看清屏幕的其餘部分,當他們在上面你的手覆蓋整個屏幕.. – networkprofile 2011-04-26 16:11:42

+0

你說得對,也許我應該把它動起來,我會考慮的 – networkprofile 2011-04-26 16:25:24

回答

2

這裏有很多額外的佈局,但看起來像真正的問題是layoutSearch是一個垂直LinearLayout有兩個孩子,但第一個孩子的高度設置爲fill_parent,所以你自然不會看到第二個。嘗試將其高度設置爲0px,但給它一個layout_weight,1,並且它應該擴展以獲取其下面的EditText所沒有的所有可用空間。

+0

我改變了高度'wrap_content',它的工作現在。還有一個問題:你說有很多過多的佈局..你如何建議我以更好的方式做到這一點?謝謝你的幫助! – networkprofile 2011-04-26 16:14:00

+0

哦,我剛纔只是說,相對於你的問題,所有的容器周圍的東西'layoutSearch'是不相關的。不過,如果你願意的話,你可以用RelativeLayout將事情弄平。 – 2011-04-26 16:19:35

+0

啊對,我不知道哪一部分是造成問題,這就是爲什麼我張貼的一切。無論如何,再次感謝您的幫助! – networkprofile 2011-04-26 16:23:43