填充具有`wrap_content`作为高度的视图

时间:2016-04-27 22:23:52

标签: android xml

所以我正在使用RecyclerView和一些卡片。我想在点击时在卡片上叠加一个叠加层,它应覆盖所有内容,但不会改变视图的大小。由于内容具有不同的尺寸,因此无法对卡的大小进行硬编码。

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

    <!--contents and stuff-->

    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#000" />

</RelativeLayout>

上面的例子几乎就是我想要实现的,但这显然不起作用,因为ViewRelativeLayout的高度相互指向。

如何让View覆盖RelativeLayout内的所有内容?

编辑
澄清:我遇到的问题与点击,覆盖或类似的事情无关。我只是覆盖了RelativeLayout

1 个答案:

答案 0 :(得分:0)

积分转到thunder413,以便在评论中建议FrameLayout

基本上,我所要做的只是将RelativeLayout(如我的问题中所示)封装在FrameLayout中,然后将View移出RelativeLayout FrameLayout

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

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

        <!--contents and stuff-->

    </RelativeLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#000" />

</FrameLayout>