【问题标题】:Android: How to set layout height automaticAndroid:如何自动设置布局高度
【发布时间】:2016-04-25 19:58:52
【问题描述】:
我想像这张图一样自动设置布局高度:
因为如果我在fill_parent 或match_parent 中设置布局高度,它看起来像这样:
我想要fill_parent 之类的东西,但在中间。
抱歉英语不好,希望你能理解。
【问题讨论】:
标签:
android
layout
height
【解决方案2】:
<?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>
【解决方案3】:
你可以使用
android:layout_width="wrap_content"
android:layout_height="wrap_content"
根据您的内容自动设置布局
【解决方案4】:
让我给出一个疯狂的答案:)
首先确保设置约束,然后像这样设置高度android:layout_height="zeltrax",然后运行应用程序并猜测什么构建输出会给你一个错误,其中包含适合该屏幕的精确 dp 数。
像这样:AAPT: error: 'zeltrax' is incompatible with attribute layout_height (attr) dimension|enum [fill_parent=4294967295, match_parent=4294967295, wrap_content=4294967294]
你必须在高度上使用wrap_content=4294967294,比如android:layout_height="4294967294dp",然后你就可以开始了。
稍后谢谢我:)