Android:如何自动设置布局高度

时间:2016-01-20 05:23:05

标签: android layout height

我想自动设置布局高度,如下图所示:

http://i.stack.imgur.com/i7NOx.png

因为如果我在fill_parentmatch_parent设置布局高度,它看起来像这样:

enter image description here

我想要一个像fill_parent但在中间的东西。

抱歉英语不好,希望你能理解。

3 个答案:

答案 0 :(得分:1)

使用布局的布局权重属性

答案 1 :(得分:0)

您可以使用

 android:layout_width="wrap_content"
 android:layout_height="wrap_content"

根据您的内容自动设置布局

答案 2 :(得分:0)

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

    <LinearLayout
        android:id="@+id/aa"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:orientation="vertical">

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

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

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/bb"
        android:layout_below="@+id/aa"></LinearLayout>

    <LinearLayout
        android:id="@+id/bb"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical">

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

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

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

</RelativeLayout>
相关问题