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 澄清布局_Android_Xml_Layout - Fatal编程技术网

Android 澄清布局

Android 澄清布局,android,xml,layout,Android,Xml,Layout,这是我的布局: <ScrollView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="50dp"> <LinearLayout android:layout_width="match_parent" android:l

这是我的布局:

    <ScrollView
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:layout_marginTop="50dp">

        <LinearLayout
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:orientation="vertical">

            <LinearLayout
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:orientation="horizontal"
               android:background="@drawable/under_line_edit">

                <ImageView
                   android:layout_width="wrap_content"
                   android:layout_height="match_parent"
                   android:background="@drawable/ic_assignment" />

                <EditText
                   android:id="@+id/editName"
                   android:textColor="#000000"
                   android:layout_width="match_parent"
                   android:layout_height="match_parent"
                   android:background="@drawable/under_line_edit"/>
            </LinearLayout>


            <LinearLayout
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:orientation="horizontal"
               android:layout_marginTop="30dp"
               android:background="@drawable/under_line_edit">

                <ImageView
                   android:layout_width="wrap_content"
                   android:layout_height="match_parent"
                   android:id="@+id/img"
                   android:background="@drawable/ic_person_outline" />

                <EditText
                   android:id="@+id/editUsername"
                   android:textColor="#000000"
                   android:layout_width="match_parent"
                   android:layout_height="match_parent"
                   android:background="@drawable/under_line_edit"/>
            </LinearLayout>

    </ScrollView>

我不明白为什么如果我将match_parent放在imageView和editTex上,后者不会占据整个屏幕的高度。
相反,我得到了我想要的两行,但我不明白为什么

为什么?

请尝试以下方法:

<ScrollView
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:layout_marginTop="50dp">

    <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:orientation="vertical">

        <LinearLayout
           android:layout_width="match_parent"
           android:layout_height="0dp"
           android:layout_weight="1"
           android:orientation="horizontal"              
           android:background="@drawable/under_line_edit">

            <ImageView
               android:layout_width="wrap_content"
               android:layout_height="match_parent"
               android:background="@drawable/ic_assignment" />

            <EditText
               android:id="@+id/editName"
               android:textColor="#000000"
               android:layout_width="match_parent"
               android:layout_height="match_parent"
               android:background="@drawable/under_line_edit"/>
        </LinearLayout>


        <LinearLayout
           android:layout_width="match_parent"
           android:layout_height="0dp"
           android:layout_weight="1"
           android:orientation="horizontal"
           android:layout_marginTop="30dp"
           android:background="@drawable/under_line_edit">

            <ImageView
               android:layout_width="wrap_content"
               android:layout_height="match_parent"
               android:id="@+id/img"
               android:background="@drawable/ic_person_outline" />

            <EditText
               android:id="@+id/editUsername"
               android:textColor="#000000"
               android:layout_width="match_parent"
               android:layout_height="match_parent"
               android:background="@drawable/under_line_edit"/>
        </LinearLayout>

</ScrollView>


因此,目前它在每个
ImageView
旁边提供了两个
ImageView
图像视图,每个
ImageView
下面都有一个
EditText
?是的,我不明白为什么我在高度上使用match\u parent,这是因为在彼此下面有两个线性布局,并且它们的方向都设置为水平。是的,但是如果我把整个屏幕的高度,它不应该占据整个屏幕?试试这个。。在两个
线性布局中
android:layout_weight=“1”
并将两个
线性布局的高度设置为0dp。这将使其与父级匹配并占用相等的空间。