Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将屏幕除以百分比_Android_Android Layout - Fatal编程技术网

Android 将屏幕除以百分比

Android 将屏幕除以百分比,android,android-layout,Android,Android Layout,我试图在中创建一个相对布局,当它垂直布置3个视图时。第一个视图是文本,应该占屏幕的10%。第二个视图是图像,应该占据屏幕的50%。第三个视图是文本,应该占剩下的40% 我这样做的方式是,通过手动调整图像的尺寸,并通过观察估计它接近我想要的。我相信这不是正确的方法。那我怎么做呢?基本上,我如何按百分比划分屏幕,以及如何使用相对布局进行划分 谢谢您可以使用LinearLayout和android:layou-weight属性: <?xml version="1.0" encoding="utf

我试图在中创建一个相对布局,当它垂直布置3个视图时。第一个视图是文本,应该占屏幕的10%。第二个视图是图像,应该占据屏幕的50%。第三个视图是文本,应该占剩下的40%

我这样做的方式是,通过手动调整图像的尺寸,并通过观察估计它接近我想要的。我相信这不是正确的方法。那我怎么做呢?基本上,我如何按百分比划分屏幕,以及如何使用相对布局进行划分


谢谢

您可以使用
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。这是greatIs
weightSum
真的需要吗?文件上说:“如果未指定,则通过将所有子项的
layou权重
相加来计算总和。”+1表示正确答案,而另一个答案则更具描述性。