LinearLayouts 重叠(在 RecyclerView 的 row_layout.xml 中)
LinearLayouts Overlapping (in RecyclerView's row_layout.xml)
我尝试为此搜索多个 Whosebug 帖子,因为似乎有很多。
我尝试了很多解决方案,包括:
改变 ordering/nesting
添加 android:layout_above
添加 android:align_bottom
添加 android:align_ParentBottom
等...
XML 看起来不错,但不确定为什么重叠?
图片:
row_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="100dp"
>
<LinearLayout
android:id="@+id/rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="3dp"
android:weightSum="3"
>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginEnd="10dp"
android:layout_weight=".45"
android:src="@drawable/user" />
<EditText
android:id="@+id/nameOfBusinessET"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2.55"
android:hint="@string/nameOfBusiness"
android:inputType="textPersonName"
android:imeOptions="actionDone"
android:textColorHint="@color/grey" />
</LinearLayout>
<LinearLayout
android:id="@+id/rl2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="3dp"
android:weightSum="3"
>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginEnd="10dp"
android:layout_weight=".45"
android:src="@drawable/user" />
<EditText
android:id="@+id/bizLocationET"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2.55"
android:hint="Location"
android:inputType="textPersonName"
android:imeOptions="actionDone"
android:textColorHint="@color/grey" />
</LinearLayout>
</RelativeLayout>
您使用过RelativeLayout
,RelativeLayout
是一个视图组,在相对位置显示子视图。每个视图的位置可以指定为相对于同级元素(例如另一个视图的左侧或下方)或相对于父 RelativeLayout
区域的位置(例如与底部、左侧或中心对齐) ).
改变你的
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="100dp">
......
</RelativeLayout>
和
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical">
.....
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="100dp"
>
<LinearLayout
android:id="@+id/rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="3dp"
android:weightSum="3"
>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginEnd="10dp"
android:layout_weight=".45"
android:src="@drawable/user" />
<EditText
android:id="@+id/nameOfBusinessET"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2.55"
android:hint="@string/nameOfBusiness"
android:inputType="textPersonName"
android:imeOptions="actionDone"
android:textColorHint="@color/grey" />
</LinearLayout>
<LinearLayout
android:id="@+id/rl2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="3dp"
android:weightSum="3"
>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginEnd="10dp"
android:layout_weight=".45"
android:src="@drawable/user" />
<EditText
android:id="@+id/bizLocationET"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2.55"
android:hint="Location"
android:inputType="textPersonName"
android:imeOptions="actionDone"
android:textColorHint="@color/grey" />
</LinearLayout>
希望您正在寻找这个,将您的 parent RelativeLayout
更改为 LinearLayout
并使方向垂直。
另外 LinearLayout
表示您可以一个接一个地对齐视图(垂直/水平)。默认情况下 LinearLayout
是水平
哪里
RelativeLayout
表示基于其 parent 的观点与其他观点的关系。
只需在您的 LinearLayout 中添加一个具有 ID rl2
android:layout_below="@+id/rl"
的属性
所以你的布局应该是这样的。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="100dp">
<LinearLayout
android:id="@+id/rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="3dp"
android:weightSum="3">
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginEnd="10dp"
android:layout_weight=".45"
android:src="@drawable/user"/>
<EditText
android:id="@+id/nameOfBusinessET"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2.55"
android:hint="@string/done"
android:imeOptions="actionDone"
android:inputType="textPersonName"
android:textColorHint="@color/hint_color"/>
</LinearLayout>
<LinearLayout
android:id="@+id/rl2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/rl"
android:padding="3dp"
android:weightSum="3">
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginEnd="10dp"
android:layout_weight=".45"
android:src="@drawable/user"/>
<EditText
android:id="@+id/bizLocationET"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2.55"
android:hint="Location"
android:imeOptions="actionDone"
android:inputType="textPersonName"
android:textColorHint="@color/hint_color"/>
</LinearLayout>
</RelativeLayout>
试试这个布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="100dp">
<LinearLayout
android:id="@+id/rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="3dp"
android:weightSum="2">
<LinearLayout
android:id="@+id/rl1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:padding="3dp">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:src="@drawable/temp" />
<EditText
android:id="@+id/bizLocationET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:hint="Location"
android:imeOptions="actionDone"
android:inputType="textPersonName"
android:textColorHint="@color/colorGray" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:padding="3dp">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:src="@drawable/temp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:hint="Name of business"
android:imeOptions="actionDone"
android:inputType="textPersonName"
android:textColorHint="@color/colorGray" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Take one Verical Linear layout
-> Two horizontal linear layout
In every horizontal layout take image view
and edittext
.
我尝试为此搜索多个 Whosebug 帖子,因为似乎有很多。 我尝试了很多解决方案,包括:
改变 ordering/nesting 添加 android:layout_above 添加 android:align_bottom 添加 android:align_ParentBottom
等...
XML 看起来不错,但不确定为什么重叠?
图片:
row_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="100dp"
>
<LinearLayout
android:id="@+id/rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="3dp"
android:weightSum="3"
>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginEnd="10dp"
android:layout_weight=".45"
android:src="@drawable/user" />
<EditText
android:id="@+id/nameOfBusinessET"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2.55"
android:hint="@string/nameOfBusiness"
android:inputType="textPersonName"
android:imeOptions="actionDone"
android:textColorHint="@color/grey" />
</LinearLayout>
<LinearLayout
android:id="@+id/rl2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="3dp"
android:weightSum="3"
>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginEnd="10dp"
android:layout_weight=".45"
android:src="@drawable/user" />
<EditText
android:id="@+id/bizLocationET"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2.55"
android:hint="Location"
android:inputType="textPersonName"
android:imeOptions="actionDone"
android:textColorHint="@color/grey" />
</LinearLayout>
</RelativeLayout>
您使用过RelativeLayout
,RelativeLayout
是一个视图组,在相对位置显示子视图。每个视图的位置可以指定为相对于同级元素(例如另一个视图的左侧或下方)或相对于父 RelativeLayout
区域的位置(例如与底部、左侧或中心对齐) ).
改变你的
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="100dp">
......
</RelativeLayout>
和
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical">
.....
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="100dp"
>
<LinearLayout
android:id="@+id/rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="3dp"
android:weightSum="3"
>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginEnd="10dp"
android:layout_weight=".45"
android:src="@drawable/user" />
<EditText
android:id="@+id/nameOfBusinessET"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2.55"
android:hint="@string/nameOfBusiness"
android:inputType="textPersonName"
android:imeOptions="actionDone"
android:textColorHint="@color/grey" />
</LinearLayout>
<LinearLayout
android:id="@+id/rl2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="3dp"
android:weightSum="3"
>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginEnd="10dp"
android:layout_weight=".45"
android:src="@drawable/user" />
<EditText
android:id="@+id/bizLocationET"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2.55"
android:hint="Location"
android:inputType="textPersonName"
android:imeOptions="actionDone"
android:textColorHint="@color/grey" />
</LinearLayout>
希望您正在寻找这个,将您的 parent RelativeLayout
更改为 LinearLayout
并使方向垂直。
另外 LinearLayout
表示您可以一个接一个地对齐视图(垂直/水平)。默认情况下 LinearLayout
是水平
哪里
RelativeLayout
表示基于其 parent 的观点与其他观点的关系。
只需在您的 LinearLayout 中添加一个具有 ID rl2
android:layout_below="@+id/rl"
所以你的布局应该是这样的。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="100dp">
<LinearLayout
android:id="@+id/rl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="3dp"
android:weightSum="3">
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginEnd="10dp"
android:layout_weight=".45"
android:src="@drawable/user"/>
<EditText
android:id="@+id/nameOfBusinessET"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2.55"
android:hint="@string/done"
android:imeOptions="actionDone"
android:inputType="textPersonName"
android:textColorHint="@color/hint_color"/>
</LinearLayout>
<LinearLayout
android:id="@+id/rl2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/rl"
android:padding="3dp"
android:weightSum="3">
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginEnd="10dp"
android:layout_weight=".45"
android:src="@drawable/user"/>
<EditText
android:id="@+id/bizLocationET"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2.55"
android:hint="Location"
android:imeOptions="actionDone"
android:inputType="textPersonName"
android:textColorHint="@color/hint_color"/>
</LinearLayout>
</RelativeLayout>
试试这个布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="100dp">
<LinearLayout
android:id="@+id/rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="3dp"
android:weightSum="2">
<LinearLayout
android:id="@+id/rl1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:padding="3dp">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:src="@drawable/temp" />
<EditText
android:id="@+id/bizLocationET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:hint="Location"
android:imeOptions="actionDone"
android:inputType="textPersonName"
android:textColorHint="@color/colorGray" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:padding="3dp">
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginEnd="10dp"
android:layout_weight="1"
android:src="@drawable/temp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:hint="Name of business"
android:imeOptions="actionDone"
android:inputType="textPersonName"
android:textColorHint="@color/colorGray" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Take one
Verical Linear layout
-> Twohorizontal linear layout
In every horizontal layout takeimage view
andedittext
.