如何使用两个部分在我的情况定义布局 [英] How to define a layout with two parts in my case
问题描述
我想定义布局,看起来是这样的:
我的意思是要对屏幕上方的黄色区域,保持它始终显示在屏幕上,同时,绿色的区域是<滚动型>
。
我想定义两个单独的布局文件,例如 yellow_area.xml &安培; green_area.xml ,然后将它们包含在一个的main.xml 。
但如何保持黄色区域总是可见的放大器;有绿地面积滚动? (这是使黄色区域看起来是上面的绿色区域)
我想定义两个单独的布局文件,例如yellow_area.xml&安培; green_area.xml,包括他们在一个main.xml中。
块引用>如果你想要重新使用一个或两个人,那么这样做或使用
片段
是一个好主意......任何你的情况最好。
但如何保持黄色区域总是可见的放大器;有绿地面积滚动? (这是使黄色区域看起来是上面的绿色区域)
块引用>您应该能够通过使用 RelativeLayout的并使用属性
的android:layout_below =@ ID / topLayout
在
<包括>
标记为贵的greeen布局
假设topLayout
是ID
你的黄布局
。修改
我觉得我上面的回答没有工作,由于
查看
S中包括布局内
数。使用的LinearLayout
为父布局
,并使用layout_weight
内每个孩子的布局
(和的ListView
解决问题。类似XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直
机器人:layout_gravity =CENTER_HORIZONTAL
机器人:重力=CENTER_HORIZONTAL
>
&所述;! - 包括一个title_layout - >
<包括
机器人:ID =@ + ID / upper_area
机器人:layout_width =FILL_PARENT
机器人:layout_height =0dp
布局=@布局/ title_layout
25:机器人layout_weight = /> //这里增加重量 <! - 以下title_layout列表视图 - >
< ListView控件
机器人:ID =@ + ID / DATA_LIST
机器人:layout_width =FILL_PARENT
机器人:layout_height =0dp
75:机器人layout_weight = /> // 和这里
< / LinearLayout中>使用
layout_weight
与垂直
取向高度
必须设置为0dp
(layout_width =0dp
为水平方向)I would like to define a layout which looks like this:
What I mean is to have the yellow area on top of screen, keep it always visible on screen, while, the green area is a
<ScrollView>
.I am thinking to define two separate layout files, e.g. yellow_area.xml & green_area.xml, and includes them in one main.xml.
But how to keep yellow area always visible & have green area scrollable? (That's to make yellow area looks like it is above green area)
解决方案I am thinking to define two separate layout files, e.g. yellow_area.xml & green_area.xml, and includes them in one main.xml.
If you are wanting to re-use one or both of them then doing this or using
fragments
is a fine idea...whichever works best in your case.But how to keep yellow area always visible & have green area scrollable? (That's to make yellow area looks like it is above green area)
You should be able to accomplish this by using a RelativeLayout and using the property
android:layout_below="@id/topLayout"
in the
<include>
tag for your "greeenlayout
assuming thattopLayout
is theid
of your "yellow"layout
.Edit
I think my above answer didn't work due to the number of
View
s inside of the includedlayout
. Using aLinearLayout
as theparent layout
and usinglayout_weight
inside of each childlayout
( andListView
fixes the problem. Something like?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>
Using
layout_weight
with avertical
orientation theheight
must be set to0dp
(layout_width="0dp"
for horizontal orientation)这篇关于如何使用两个部分在我的情况定义布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!