Layout for Android. Fluid layout and a fixed layou

2019-07-21 00:26发布

I've to develop an Android application that needs to show data using a similar layout. I need two parts of screen:

  • A layout with a fluid height that vary on resolution of device
  • Second layout that show content in a fixed size

How to do this? I've used relativelayout and linearlayout but I haven't found a solution. Could you help me?

Image representing my layout wireframe

2条回答
狗以群分
2楼-- · 2019-07-21 00:44

For a LinearLayout set top layout to android:layout_weight="1" (and height to 0dp) and bottom layout_height to either a fixed value or android:layout_height="wrap_content"

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <View
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#FF0000" />

    <View
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="#00FF00" />

</LinearLayout>
查看更多
虎瘦雄心在
3楼-- · 2019-07-21 00:46
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/fixedlayout"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:orientation="vertical"
        android:id="@+id/fluidlayout" >
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:orientation="vertical"
        android:id="@+id/fixedlayout" >
    </LinearLayout>

</RelativeLayout>

More efficient solution using LinearLayout

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="200dp" >
    </LinearLayout>

</LinearLayout>
查看更多
登录 后发表回答