当父级 layout_width / layout_height 设置为儿子 layout_width / layout_height 时,我试图了解UI行为到 match_parent 。我在stackoverflow combining wrap_content on parent and fill_parent on child
中发现了一个老问题但是,这位邮寄作家试图使他的所有儿子(在他的情况下为纽扣)都处于同一高度,答复是针对此目的,而不是针对如何解决这一冲突。 例如,在下面的代码中,我编写了:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="25dp"
android:layout_margin="@dimen/cardview_compat_inset_shadow">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:textStyle="bold" />
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
我运行了这段代码, CardView 宽度占据了整个屏幕(似乎 CardView 中的layout_width( match_parent )克服了layout_width( RelativeLayout 中的 wrap_content )。而 CardView 高度仅占据了两个TextViews,而不是整个屏幕(似乎layout_width( wrap_content RelativeLayout 中的em>)克服了 CardView
中的layout_width( match_parent )我找不到应该如何设置冲突的任何“规则”。 我希望有人能帮助我理解有关如何解决此冲突的逻辑或事实?