拉伸并填充中间布局 Android
Stretch and fill middle Layout Android
我有一个 Main Relative Layout(height,width=fill parent),里面有 3 个布局:
1st: Frame Layout(width=fill_parent/height=wrap_content)
2nd: Linear Layout(width=fill_parent/height=wrap_content/layoutbelow 1st)
3rd: Relative Layout(height=wrap_content/width=fill parent/layout_alignParentBottom="true"/ layoutbelow 2nd)
我希望第 3 个布局位于屏幕底部,第 1 个位于屏幕顶部,第 2 个布局填充中间的 space。我该怎么做呢?我按照这个 link:Android LinearLayout fill-the-middle 并尝试设置 layout_height="0px" 和 layout_weight="1" 但它没有用。谁能帮我解决这个问题?
谢谢
试试这个:
第 1:框架布局(宽度=fill_parent/height=wrap_content)
第二:线性布局(宽度=fill_parent/height=wrap_content/layoutbelow第一/布局高于第三)
第三:相对布局(height=wrap_content/width=fill parent/layout_alignParentBottom="true")
例如:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btnButton1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="1"/>
<Button
android:id="@+id/btnButton2"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="2"
android:layout_below="@+id/btnButton1"
android:layout_above="@+id/btnButton3"/>
<Button
android:id="@+id/btnButton3"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="3"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
IIRC RelativeLayout 不支持 layout_weight。
所以你需要这样的东西:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_wight="1" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
我有一个 Main Relative Layout(height,width=fill parent),里面有 3 个布局:
1st: Frame Layout(width=fill_parent/height=wrap_content)
2nd: Linear Layout(width=fill_parent/height=wrap_content/layoutbelow 1st)
3rd: Relative Layout(height=wrap_content/width=fill parent/layout_alignParentBottom="true"/ layoutbelow 2nd)
我希望第 3 个布局位于屏幕底部,第 1 个位于屏幕顶部,第 2 个布局填充中间的 space。我该怎么做呢?我按照这个 link:Android LinearLayout fill-the-middle 并尝试设置 layout_height="0px" 和 layout_weight="1" 但它没有用。谁能帮我解决这个问题?
谢谢
试试这个:
第 1:框架布局(宽度=fill_parent/height=wrap_content)
第二:线性布局(宽度=fill_parent/height=wrap_content/layoutbelow第一/布局高于第三)
第三:相对布局(height=wrap_content/width=fill parent/layout_alignParentBottom="true")
例如:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btnButton1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="1"/>
<Button
android:id="@+id/btnButton2"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="2"
android:layout_below="@+id/btnButton1"
android:layout_above="@+id/btnButton3"/>
<Button
android:id="@+id/btnButton3"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="3"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
IIRC RelativeLayout 不支持 layout_weight。
所以你需要这样的东西:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_wight="1" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>