Space 在布局中,即使在分配重量后
Space in the layout even after distributing weight
为什么android底部有空格本来应该用分布式weight
将 textview 的高度更改为 fill_parent
android:height="fill_parent"
您必须使用属性 android:weightSum="value"
设置一个 weightSum
值到 LinearLayout
。
试试这个:
<?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"
android:weightSum="17">
<ImageView
android:src="@drawable/ocean"
android:layout_width="match_parent"
android:layout_height="0dp"
android:scaleType="centerCrop"
android:layout_weight="5"/>
<TextView
android:text="You're Invited"
android:layout_width="match_parent"
android:layout_height="0dp"
android:textColor="@android:color/white"
android:textSize="54sp"
android:background="#009688"
android:layout_weight="10"/>
<TextView
android:text="Bonfire at the beach"
android:layout_width="match_parent"
android:layout_height="0dp"
android:textColor="@android:color/white"
android:textSize="34sp"
android:background="#009688"
android:layout_weight="2"/>
</LinearLayout>
输出:
为什么android底部有空格本来应该用分布式weight
将 textview 的高度更改为 fill_parent
android:height="fill_parent"
您必须使用属性 android:weightSum="value"
设置一个 weightSum
值到 LinearLayout
。
试试这个:
<?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"
android:weightSum="17">
<ImageView
android:src="@drawable/ocean"
android:layout_width="match_parent"
android:layout_height="0dp"
android:scaleType="centerCrop"
android:layout_weight="5"/>
<TextView
android:text="You're Invited"
android:layout_width="match_parent"
android:layout_height="0dp"
android:textColor="@android:color/white"
android:textSize="54sp"
android:background="#009688"
android:layout_weight="10"/>
<TextView
android:text="Bonfire at the beach"
android:layout_width="match_parent"
android:layout_height="0dp"
android:textColor="@android:color/white"
android:textSize="34sp"
android:background="#009688"
android:layout_weight="2"/>
</LinearLayout>
输出: