我想定义一个如下所示的布局:
我的意思是让黄色区域位于屏幕顶部,使其始终在屏幕上可见,而绿色区域是<ScrollView>
.
我正在考虑定义两个单独的布局文件,例如Yellow_area.xml和green_area.xml,并将它们包含在一个main.xml中。
但是如何保持黄色区域始终可见并且绿色区域可滚动?(这是为了让黄色区域看起来在绿色区域之上)
我想定义一个如下所示的布局:
我的意思是让黄色区域位于屏幕顶部,使其始终在屏幕上可见,而绿色区域是<ScrollView>
.
我正在考虑定义两个单独的布局文件,例如Yellow_area.xml和green_area.xml,并将它们包含在一个main.xml中。
但是如何保持黄色区域始终可见并且绿色区域可滚动?(这是为了让黄色区域看起来在绿色区域之上)
我正在考虑定义两个单独的布局文件,例如 Yellow_area.xml 和 green_area.xml,并将它们包含在一个 main.xml 中。
如果您想重复使用其中一个或两个,那么这样做或使用fragments
是一个好主意……以最适合您的情况为准。
但是如何保持黄色区域始终可见并且绿色区域可滚动?(这是为了让黄色区域看起来在绿色区域之上)
您应该能够通过使用RelativeLayout并使用属性来完成此操作
android:layout_below="@id/topLayout"
在<include>
您的“绿色”标签中,layout
假设那topLayout
是id
您的“黄色” layout
。
编辑
我认为我的上述答案不起作用,因为 include 中的View
s数量很多layout
。使用 aLinearLayout
作为 theparent layout
并layout_weight
在每个孩子的内部使用layout
( 并ListView
解决问题。像
?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
>
<!--included a title_layout-->
<include
android:id="@+id/upper_area"
android:layout_width="fill_parent"
android:layout_height="0dp"
layout="@layout/title_layout"
android:layout_weight=".25"/> // add weight here
<!--Listview below title_layout-->
<ListView
android:id="@+id/data_list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight=".75" /> // and here
</LinearLayout>
layout_weight
与vertical
方向一起使用,height
必须设置为0dp
(layout_width="0dp"
对于水平方向)
使用下面的布局和框架布局作为片段的支架。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="@+id/fragment_holder"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2">
<!--Whatever you want in the scrollview-->
</ScrollView>
</LinearLayout>
这应该有效。使用重量来改变每个部分应该占用多少。
<LinearLayout
...android:orientation="vertical"
>
<TextView
...android:layout_height="fill_parent"
android:layout_weight=".25"/>
<ScrollView
...android:layout_height="fill_parent"
android:layout_weight=".75"/>
/>
我只包括了重要的部分,您将需要根据您的需要填写更多信息。那个 textview 可以是任何东西,看起来它可能需要像另一个布局一样把那个图片放在那里,旁边有文本。