Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.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 如何进行线性布局';a:a:a:你的体重是多少?_Android_Android Layout_Android View_Android Constraintlayout - Fatal编程技术网

Android 如何进行线性布局';a:a:a:你的体重是多少?

Android 如何进行线性布局';a:a:a:你的体重是多少?,android,android-layout,android-view,android-constraintlayout,Android,Android Layout,Android View,Android Constraintlayout,我有以下布局,我希望与线性布局中的weightSum和weight具有相同的行为 <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"

我有以下布局,我希望与
线性布局中的
weightSum
weight
具有相同的行为

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto">

    <LinearLayout
            android:id="@+id/linear_layout_1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginStart="10dp"
            android:layout_marginTop="10dp"
            android:background="#a4c639"
            android:thelayout_constraintHorizontal_weight="5"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
    >
        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Title"
        />

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Main information"
        />
    </LinearLayout>



    <LinearLayout
            android:id="@+id/linear_layout_2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:background="#a4c639"
            android:thelayout_constraintHorizontal_weight="5"

            android:layout_marginStart="10dp"
            app:layout_constraintTop_toTopOf="@id/linear_layout_1"
            app:layout_constraintStart_toEndOf="@id/linear_layout_1"
            app:layout_constraintTop_toBottomOf="@id/linear_layout_1"
    >
        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Title"
        />

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="foo"
        />
    </LinearLayout>

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Bar"
            android:thelayout_constraintHorizontal_weight="5"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toEndOf="@id/linear_layout_2"
            app:layout_constraintTop_toTopOf="@id/linear_layout_2"
            app:layout_constraintBottom_toBottomOf="@id/linear_layout_2"
            android:background="#a4c639"
    />

</android.support.constraint.ConstraintLayout>  


我想所有的3个小部件都占据1/3的空间。我该怎么做

要将权重与
ConstraintLayout
一起使用,必须确保所有要加权的视图形成一个链。在本例中,我们将处理水平链,这意味着每个视图的开始+结束(或左+右)必须约束到其邻居或父视图

例如:

<View
    android:id="@+id/first"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toStartOf="@id/second"
    .../>

<View
    android:id="@+id/second"
    app:layout_constraintStart_toEndOf="@id/first"
    app:layout_constraintEnd_toStartOf="@id/third"
    .../>

<View
    android:id="@+id/third"
    app:layout_constraintStart_toEndOf="@id/second"
    app:layout_constraintEnd_toEndOf="parent"
    .../>
如果要更改视图的加权方式,必须指定每个视图的权重(除了将宽度设置为
0dp
)。此处,中间视图将是两个侧视图的两倍大:

<View
    android:id="@+id/first"
    app:layout_constraintHorizontal_weight="1"
    .../>

<View
    android:id="@+id/second"
    app:layout_constraintHorizontal_weight="2"
    .../>

<View
    android:id="@+id/third"
    app:layout_constraintHorizontal_weight="1"
    .../>


对于尚未声明的视图,我们不需要在“尝试解析约束”之前使用
app:layout\u constraintEnd\u toStartOf=“@+id/second”
RelativeLayout
?AAPT的现代版本将解析布局并为每个视图生成id,因此,您可以在第一个视图中使用
@id/second
,即使
@+id/second
稍后会出现在文件中。尽管在任何地方使用
@+id
语法都没有问题。如果你使用
@id
语法,你只会从lint那里得到稍微好一点的帮助。太棒了!如果在链中,我有一个充当分隔器的视图,即宽度2dp,因为仅对于宽度为0dp的视图,约束将正常工作?
<View
    android:id="@+id/first"
    app:layout_constraintHorizontal_weight="1"
    .../>

<View
    android:id="@+id/second"
    app:layout_constraintHorizontal_weight="2"
    .../>

<View
    android:id="@+id/third"
    app:layout_constraintHorizontal_weight="1"
    .../>