【发布时间】:2021-09-06 05:59:30
【问题描述】:
我在一个相对布局中有两个线性布局。
无论我做什么,这两个线性布局都会相互重叠。
我想将它们排列成不重叠的行顺序(一个在另一个之下)。
如果线性布局有这么多问题,我正在考虑使用表格布局,但想在这里问一下线性布局是否有一些好处。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/linearlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1">
<!--This layout only holds a TextView
inside a CardView-->
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:text="this is another test this is another test"
android:textColor="#0C0909"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/linear_one"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<ImageView
android:id="@+id/image_one"
android:layout_width="match_parent"
android:src="@mipmap/nvoids_logo_foreground"
android:layout_height="100dp"/>
</LinearLayout>
</RelativeLayout>
【问题讨论】:
-
为什么不使用约束布局?
-
@Raghunandan 是哪一个?用 ConstraintLayout 替换 RelativeLayout 或 LinearLayout?
-
是的,使用一个约束布局
标签: android android-layout layout