【发布时间】:2014-02-17 15:40:26
【问题描述】:
我希望创建这种类型的布局......
左侧用xml创建的一个静态片段
在底部的 xml 中创建的一个静态片段作为页脚
在顶部的 xml 中创建的一个静态片段作为标题
最后
基于从外部到活动的不同广播在运行时创建的不同动态片段的一个容器。
这是一个视觉效果......
如何在 xml 中构造这个活动的布局?
【问题讨论】:
标签: android android-fragments fragment
我希望创建这种类型的布局......
左侧用xml创建的一个静态片段
在底部的 xml 中创建的一个静态片段作为页脚
在顶部的 xml 中创建的一个静态片段作为标题
最后
基于从外部到活动的不同广播在运行时创建的不同动态片段的一个容器。
这是一个视觉效果......
如何在 xml 中构造这个活动的布局?
【问题讨论】:
标签: android android-fragments fragment
使用RelativeLayout 放置顶部和底部片段,然后在它们之间添加一个包含列表片段和最后一个动态片段的水平LinearLayout。片段的尺寸可以放在dimens文件中,我在xml中硬编码48dp;列表区域也占宽度的 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>
或者,如果您只想拥有视图组而没有 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>
【讨论】:
dynamically across the board no fragments in xml是什么意思吗?
fragment 标签。要我编辑示例吗?