Android 将屏幕除以百分比
我试图在中创建一个相对布局,当它垂直布置3个视图时。第一个视图是文本,应该占屏幕的10%。第二个视图是图像,应该占据屏幕的50%。第三个视图是文本,应该占剩下的40% 我这样做的方式是,通过手动调整图像的尺寸,并通过观察估计它接近我想要的。我相信这不是正确的方法。那我怎么做呢?基本上,我如何按百分比划分屏幕,以及如何使用相对布局进行划分Android 将屏幕除以百分比,android,android-layout,Android,Android Layout,我试图在中创建一个相对布局,当它垂直布置3个视图时。第一个视图是文本,应该占屏幕的10%。第二个视图是图像,应该占据屏幕的50%。第三个视图是文本,应该占剩下的40% 我这样做的方式是,通过手动调整图像的尺寸,并通过观察估计它接近我想要的。我相信这不是正确的方法。那我怎么做呢?基本上,我如何按百分比划分屏幕,以及如何使用相对布局进行划分 谢谢您可以使用LinearLayout和android:layou-weight属性: <?xml version="1.0" encoding="utf
谢谢您可以使用
LinearLayout
和android:layou-weight
属性:
<?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">
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<View
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="5" />
<View
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="4" />
</LinearLayout>
您应该将
LinearLayout
与android:weightSum
一起使用
在根布局上使用android:weightSum=“100”
,并根据您的要求给出android:layout\u权重。以及每个视图的android:layout_height=“0dp”
<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>
希望这对您有所帮助。如果您想使用相对大小,则不能使用RelativeLayout
。相反,可以使用LinearLayout
和android:layout\u weight
来调整百分比。你应该使用LinearLayout和android:weightSum以及android:layout\u weight。这是greatIsweightSum
真的需要吗?文件上说:“如果未指定,则通过将所有子项的layou权重
相加来计算总和。”+1表示正确答案,而另一个答案则更具描述性。