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。这将使其与父级匹配并占用相等的空间。