提问者:小点点

视图取全屏高度


我在android XML布局中有以下代码。

<androidx.cardview.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/marginSmall"
    android:background="@color/white"
    app:cardCornerRadius="@dimen/item_margin">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/jobFieldList"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="@dimen/margin"
            app:fieldEditable="@{true}"
            app:fieldsMap="@{viewModel.job.jobFields}"
            app:jobFields="@{jobFields}" />

        <View
            android:id="@+id/jobFieldsNoAccess"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:alpha="0.75"
            android:background="@color/white"
            android:visibility="@{viewModel.attributes.referral.usersReferred >= 2 ? View.GONE : View.VISIBLE}" />

    </FrameLayout>

</androidx.cardview.widget.CardView>

id为jobFieldsNoAccess的视图仅基于特定条件可见。RecyclerView jobFieldList可以有一个或多个项目。

我希望视图的整个高度必须等于回收器视图的高度,这就是为什么它是match_parent的原因。但是。。。

问题是:

甚至RecyclerView jobFieldList也有一个项目占用了很小的高度。但视图jobFieldsNoAccess(如果可见)将占用整个屏幕高度。

问题并不在所有设备上。只有一些安装了Android 10的设备才会出现这个问题。

为什么视图jobFieldsNoAccess占据了整个高度?我该怎么解决呢?


共1个答案

匿名用户

为什么视图jobFieldsNoAccess占据了整个高度?

因为您使用android:layout_height=“match_parent”告诉它

我该怎么解决呢?

或使用wrap_content而不是match_parent