2014-02-16 67 views
0

我希望创建此类型的布局....带有静态和动态碎片的活动布局?

在XML创建左侧一个静态片段

在XML创建底部为页脚一个静态片段

在XML中创建在顶部作为报头一个静态片段

并且基于不同的广播从外到不同动态片段创建的运行时@最后

一个容器 活动。

这里是一个XML格式的视觉....

fragment_layout

我怎样组织这个活动的布局?

回答

1

使用RelativeLayout放置顶部和底部的片段,然后添加包含List片段和最后一个动态片段的水平的LinearLayout。片段的尺寸可以放在dimens文件中,我在xml中硬编码为48 dp;此外,列表区域占用宽度的20%,而内容区域占据其余区域。这里的东西让你开始:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <fragment 
     android:id="@+id/top_fragment" 
     android:name="com.adip.sampler.fragments.TopFragment" 
     android:layout_width="match_parent" 
     android:layout_height="48dp" 
     android:layout_alignParentTop="true" /> 

    <fragment 
     android:id="@+id/bottom_fragment" 
     android:name="com.adip.sampler.fragments.BottomFragment" 
     android:layout_width="match_parent" 
     android:layout_height="48dp" 
     android:layout_alignParentBottom="true" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/bottom_fragment" 
     android:layout_below="@+id/top_fragment" 
     android:baselineAligned="false" 
     android:orientation="horizontal" > 

     <fragment 
      android:id="@+id/list_fragment" 
      name="com.adip.sampler.fragments.ListFragment" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" /> 

     <FrameLayout 
      android:id="@+id/dynamic_area" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="4" > 
     </FrameLayout> 
    </LinearLayout> 

</RelativeLayout> 

,或者如果你想有只viewgroups并没有fragment标签,你可以有这样的布局(您可以使用任何ViewGroup代替FrameLayout,我使用它出于效率的考虑) :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <FrameLayout 
     android:id="@+id/top_fragment" 
     android:layout_width="match_parent" 
     android:layout_height="48dp" 
     android:layout_alignParentTop="true" /> 

    <FrameLayout 
     android:id="@+id/bottom_fragment" 
     android:layout_width="match_parent" 
     android:layout_height="48dp" 
     android:layout_alignParentBottom="true" /> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/bottom_fragment" 
     android:layout_below="@+id/top_fragment" 
     android:baselineAligned="false" 
     android:orientation="horizontal" > 

     <FrameLayout 
      android:id="@+id/list_fragment" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="1" /> 

     <FrameLayout 
      android:id="@+id/dynamic_area" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_weight="4" > 
     </FrameLayout> 
    </LinearLayout> 

</RelativeLayout> 
+0

如果我想做同样的事情,但动态全线XML没有碎片... – sirvon

+0

能否请你解释一下你的意思是用'动态全线xml'没有碎片? – gunar

+0

在代码中创建的所有片段,没有在xml中创建 – sirvon