【发布时间】:2020-12-24 19:31:42
【问题描述】:
我正在尝试找到一种方法来保持文本视图在复杂布局中统一对齐。有没有办法将“1B”TextView 直接定位在“1A”TextView 下方和“1C”TextView 上方,同时避免过多嵌套?
注意:“1B”和“1C”TextViews 一起在 RelativeLayout 中,作为可扩展 RecyclerView 的一部分
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/linearLayoutA">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/relativeLayoutA">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ibA"
android:src="@mipmap/ic_launcher_round"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tvA"
android:layout_toEndOf="@+id/ibA"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/relativeLayoutB">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tvB"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ivC"
android:src="@mipmap/ic_launcher_round"
android:layout_below="@id/tvB"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tvC"
android:layout_below="@id/tvB"
android:layout_toEndOf="@id/ivC"/>
</RelativeLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
【问题讨论】:
标签: android xml android-linearlayout android-percentrelativelayout