gpt4 book ai didi

android - 卡片 View : Let child item overlap

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:34:31 25 4
gpt4 key购买 nike

我的 RecyclerView 有问题。我想设计一些如下所示的 CardView:

Twitter Card

因此我需要左上角的 ImageView 与 CardView 重叠。我已经知道负边距的用法,但我的问题主要是

即使 clipToPadding 设置为 false,Cardview 中的重叠也会被裁剪掉

有人能解决这个问题吗?

最佳答案

只需将 ImageView(Twitter 图标)elevation 设置为高于 CardView elevation。

android:elevation="10dp"设置为ImageView并将card_view:cardElevation="2dp"设置为CardView.

这是一个例子:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">

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

<android.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginTop="20dp"
card_view:cardElevation="2dp"
card_view:cardCornerRadius="4dp"
card_view:cardUseCompatPadding="false"
card_view:cardPreventCornerOverlap="false">

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

<ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:src="@drawable/sample_1" />

<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/image"
android:padding="8dp"
android:background="#CCFFFFFF"
android:text="This is simple title"
android:textColor="#000000" />
</RelativeLayout>
</android.support.v7.widget.CardView>

<ImageView
android:id="@+id/icon_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:elevation="10dp"
android:src="@mipmap/ic_launcher"/>
</RelativeLayout>

</RelativeLayout>

输出:

enter image description here

希望对你有帮助~

关于android - 卡片 View : Let child item overlap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43666844/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com