2013-04-25 36 views
0

我有一個活動,在屏幕上顯示兩個片段,一個在另一個之下。頂部片段是活動的用戶界面,第二個片段是自定義ListView。我有兩個可以填充頂部插槽的片段,每個都有不同的大小。 ListView被用於兩者。Android在同一屏幕上間隔兩個片段

我面臨的問題是頂部和底部碎片之間存在主要差距。我知道它與layout_weight屬性有關,並且layout_weight是我看到控制片段命令的多少屏幕的唯一方式。

我想知道的是,如果有一種方法可以在片段加載時動態調整保留片段區域的大小,或者如果我陷入這個醜陋的差距。

這裏是我的佈局:

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

<TabHost 
    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" > 
     <TabWidget 
      android:id="@android:id/tabs" 
      android:orientation="horizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="0" 
      /> 

     <FrameLayout 
      android:id="@android:id/tabcontent" 
      android:layout_width="0dp" 
      android:layout_height="0dp" 
      android:layout_weight="0"/> 

     <FrameLayout 
      android:id="@+android:id/realtabcontent1" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"/> 
     <FrameLayout 
      android:id="@+android:id/realtabcontent2" 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight="2" /> 
    </LinearLayout> 
</TabHost> 
</LinearLayout> 
+0

這兩部分對應着兩個'FrameLayouts'?另外,對於非sdk ID,使用'@ + id/theId'(realtabcontent1和realtabcontent2不在sdk中)。 – Luksprog 2013-04-26 15:08:33

回答

0

我已經想通了。託管分段的兩個FrameLayouts的佈局高度應設置爲android:layout_height="wrap_content",並且應該刪除layout_weight行。然後,在加載到該FrameLayout的片段上動態處理間距。