【发布时间】:2019-07-30 08:20:14
【问题描述】:
我想根据显示最长子视图所需的最大宽度,将我的 Linerlayout 中存在的所有孩子设置为具有相等的宽度。
【问题讨论】:
我想根据显示最长子视图所需的最大宽度,将我的 Linerlayout 中存在的所有孩子设置为具有相等的宽度。
【问题讨论】:
将 LinearLayout 的宽度设为 wrap_content,将所有子元素的宽度设为 match_parent。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="small text"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="some long text test" />
</LinearLayout>
</LinearLayout>
【讨论】:
将父LinearLayout及其所有子项的宽度设置为match_parent
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="small text"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="some long text test" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>
</LinearLayout>
【讨论】: