And*_*per 9 android android-layout
android布局使用layout_weight.我的目标是所有组件的1/3,但有时页脚会逐渐消失,然后可见.设置从可见时,重量计算如何工作?我没有看到具有1/3重量的线性布局内的内容?
tmh*_*mho -1
确保将高度设置为 0dp,然后将所有视图的权重设置为 1
IE
<?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="0dp"
android:layout_weight="1"
android:text="Hello World, MyActivity"
android:background="#f00"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Hello World, MyActivity"
android:background="#00f"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Hello World, MyActivity"
android:background="#0f0"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
当视图设置为“消失”时,其余视图将填满屏幕的比例。即,如果将第三个视图设置为“消失”,则前 2 个视图将占用布局中每个可用空间的 50%
此外,如果您希望剩余视图仅占用 1/3 的空间(即使用 2/3 并保留 1/3 为空),请将隐藏视图设置为不可见而不消失