我正在尝试在垂直布局 3 个 View 时创建一个相对布局。第一个 View 是文本,应该占屏幕的 10%。第二个 View 是图像,应该占据屏幕的 50%。第三个 View 是文本,应该占据剩余的 40%。
我的做法是通过手动调整图片的尺寸,通过观察估计它接近我想要的。我确信这不是正确的方法。那我该怎么做呢?基本上我怎样才能明智地划分屏幕百分比,我可以用相对布局来做到这一点
谢谢
最佳答案
您应该将 LinearLayout
与 android:weightSum
一起使用。
在根布局上使用 android:weightSum="100"
并根据您的要求提供 android:layout_weight
。和 android:layout_height="0dp"
用于每个 View
。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="100" >
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10" />
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="50"
android:contentDescription="@string/image"
android:src="@drawable/ic_launcher" />
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="40" />
</LinearLayout>
希望对您有所帮助。
关于android - 按百分比划分屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20029179/