我是Android的新手。我正在为一个注册表创建一个布局。我使用基本容器作为相对布局。内部相对布局,我是保持线性布局容器,然后在这里面的所有组件的注册表。
但是在下垂两个编辑文本字段后,我可以看到这两个编辑文本字段彼此重叠,并且它作为一个可见,并且在线性容器中也向中心移动。希望大家都明白。我需要一个接一个的组件。帮助?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorAccent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="30dp"
android:background="@drawable/l_border"
android:padding="30dp"
>
<EditText
android:id="@+id/txtMobile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@drawable/ll_border"
android:backgroundTint="@color/colorAccent"
android:hint="Enter Name"
android:padding="10dp"
android:textColorHint="@color/colorBlack" />
<EditText
android:id="@+id/txtName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@drawable/ll_border"
android:backgroundTint="@color/colorAccent"
android:hint="Enter Mobile"
android:padding="10dp"
android:textColorHint="@color/colorBlack" />
</LinearLayout>
</RelativeLayout>[

发布于 2018-09-28 23:05:21
首先,除非您想在内部LinearLayout上添加一些内容,否则将其嵌套在RelativeLayout中是没有意义的。
其次,您的内部LinearLayout没有设置方向,因此默认情况下设置为horizontal,这意味着第一个编辑文本(layout_width="match_parent")将从屏幕上推出第二个EditText。
如果您将内部LinearLayot的方向设置为“垂直”,您将能够同时看到这两个字段。
如果要水平放置这两个编辑文本,请在这两个文本字段上设置"layout_width"="0; "weight"="1。或者,您可以尝试RelativeLayout定位。
更新--由@petey建议
这里有一种实现你想要的东西的方法:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" // this view is kind of pointless
android:background="@color/colorAccent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="30dp"
android:background="@drawable/l_border"
android:padding="30dp">
<EditText
android:id="@+id/txtMobile"
android:layout_width="0dp" // NOTICE THIS
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1" // // NOTICE THIS
android:background="@drawable/ll_border"
android:backgroundTint="@color/colorAccent"
android:hint="Enter Name"
android:padding="10dp"
android:textColorHint="@color/colorBlack" />
<EditText
android:id="@+id/txtName"
android:layout_width="0dp" // NOTICE THIS
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1" // NOTICE THIS
android:background="@drawable/ll_border"
android:backgroundTint="@color/colorAccent"
android:hint="Enter Mobile"
android:padding="10dp"
android:textColorHint="@color/colorBlack" />
</LinearLayout>
https://stackoverflow.com/questions/52558000
复制相似问题