Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.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线性布局中使用50%的宽度和高度_Android - Fatal编程技术网

如何在android线性布局中使用50%的宽度和高度

如何在android线性布局中使用50%的宽度和高度,android,Android,我想创建一种类似如下的布局: 我创建了相同的相对布局,但我不能放置第二个50%宽度和高度的容器 这是我的代码: <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_par

我想创建一种类似如下的布局:

我创建了相同的相对布局,但我不能放置第二个50%宽度和高度的容器

这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true">


    <android.support.constraint.ConstraintLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal"
            android:weightSum="100">

            <ImageView
                android:layout_margin="5dp"
                android:layout_width="0dp"
                android:layout_weight="50"
                android:adjustViewBounds="true"
                android:layout_height="wrap_content"
                android:src="@drawable/akhbar"
                android:id="@+id/akhbar_panel" />

            <ImageView
                android:id="@+id/amozesh_panel"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:layout_weight="50"
                android:adjustViewBounds="true"
                android:src="@drawable/amozesh" />

        </LinearLayout>

    </android.support.constraint.ConstraintLayout>

</ScrollView>

我认为此视图的更好的父视图是
ConstraintLayout
,但如果必须使用
LinearLayout
,则可以执行以下操作:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:orientation="horizontal">

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:background="#fac"
        android:text="one"/>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:gravity="center"
            android:background="#afc"
            android:text="two"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:gravity="center"
            android:background="#caf"
            android:text="three"/>

    </LinearLayout>

</LinearLayout>


我认为此视图的更好的父视图是
ConstraintLayout
,但如果必须使用
LinearLayout
,则可以执行以下操作:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:orientation="horizontal">

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:background="#fac"
        android:text="one"/>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:gravity="center"
            android:background="#afc"
            android:text="two"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:gravity="center"
            android:background="#caf"
            android:text="three"/>

    </LinearLayout>

</LinearLayout>


以下是使用ConstraintLayout解决此问题的方法:

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

    <TextView
        android:id="@+id/one"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="center"
        android:background="#fac"
        android:text="one"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@+id/two"
        app:layout_constraintBottom_toBottomOf="parent"/>

    <TextView
        android:id="@+id/two"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="center"
        android:background="#afc"
        android:text="two"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toRightOf="@+id/one"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintBottom_toTopOf="@+id/three"/>

    <TextView
        android:id="@+id/three"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="center"
        android:background="#caf"
        android:text="three"
        app:layout_constraintTop_toBottomOf="@+id/two"
        app:layout_constraintLeft_toRightOf="@+id/one"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"/>

</android.support.constraint.ConstraintLayout>

以下是使用ConstraintLayout解决此问题的方法:

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

    <TextView
        android:id="@+id/one"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="center"
        android:background="#fac"
        android:text="one"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@+id/two"
        app:layout_constraintBottom_toBottomOf="parent"/>

    <TextView
        android:id="@+id/two"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="center"
        android:background="#afc"
        android:text="two"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toRightOf="@+id/one"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintBottom_toTopOf="@+id/three"/>

    <TextView
        android:id="@+id/three"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="center"
        android:background="#caf"
        android:text="three"
        app:layout_constraintTop_toBottomOf="@+id/two"
        app:layout_constraintLeft_toRightOf="@+id/one"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"/>

</android.support.constraint.ConstraintLayout>


my image url:my image url:如果我想在容器“one”下放置另一个容器,该怎么办?我正在尝试创建此布局:但我无法放置视图这是我唯一的问题请帮助我如何放置这样的位置。。。谢谢兄弟请看我的布局图帮我兄弟thanks@ElyasErfani看起来你应该从一个垂直的线性布局开始。对于在大视图旁边有两个小视图的每一行,请使用与我的答案类似的水平线性布局。对于只有一个大视图的每一行,您可以使用一个具有
match\u parent
宽度和任意高度的视图。如果我想在容器“one”下放置另一个容器,该怎么办?我正在尝试创建此布局:但我无法放置视图这是我唯一的问题,请帮助我如何放置这样的位置。。。谢谢兄弟请看我的布局图帮我兄弟thanks@ElyasErfani看起来你应该从一个垂直的线性布局开始。对于在大视图旁边有两个小视图的每一行,请使用与我的答案类似的水平线性布局。对于只有一个大视图的每一行,您可以使用一个具有
match\u parent
宽度和任意高度的视图。