gpt4 book ai didi

android - CardView 阴影不显示,如果不止一张卡片相互重叠

转载 作者:行者123 更新时间:2023-11-29 17:15:54 29 4
gpt4 key购买 nike

下面是引用/输出截图 enter image description here

在屏幕截图中,您可以看到有四个重叠的 CardView,但顶部和右侧的角阴影没有显示在前面的卡片上,(仅显示最后一张卡片的阴影)

更新:下面 Lollipop 影子正在工作

下面是一个 CardView 的 XML 代码,我以编程方式膨胀这些 CardView 布局,并设置 XY 属性以实现重叠 View

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="@dimen/offer_card_width"
android:layout_height="97dp"
app:cardBackgroundColor="@color/windowBackgroundSecondary"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true">

<RelativeLayout
android:padding="@dimen/padding_regular"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/icon_offer"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@drawable/bg_circular_offer"
android:padding="8dp"
android:src="@drawable/ic_content_copy" />

<TextView
android:layout_marginLeft="@dimen/margin_regular"
android:id="@+id/text_offer_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/icon_offer"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/submit_button"
android:textSize="@dimen/text_size_regular"
android:text="Some content will be there" />

<TextView
android:id="@+id/text_offer_desc"
android:layout_marginTop="@dimen/margin_medium"
android:layout_marginLeft="@dimen/margin_regular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text_offer_title"
android:layout_toRightOf="@+id/icon_offer"
android:ellipsize="end"
android:maxLines="1"
android:textColor="@color/black"
android:textSize="@dimen/text_size_small"
android:text="Some content will be there, Some content will be there" />

<LinearLayout
android:layout_marginLeft="@dimen/margin_regular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/icon_offer"
android:orientation="horizontal">

<TextView
android:textColor="#6f6f6f"
android:textSize="@dimen/text_size_regular"
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Code:" />

<TextView
android:id="@+id/text_copy_code"
android:layout_marginLeft="@dimen/margin_medium"
android:layout_gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="@dimen/padding_medium"
android:ellipsize="end"
android:maxLines="1"
android:drawableRight="@drawable/ic_content_copy"
android:textColor="@color/label_header_opac"
android:textSize="@dimen/text_size_regular"
android:text="TEST2016" />
</LinearLayout>

</RelativeLayout>

</android.support.v7.widget.CardView>

下面是用于扩充 cardview 布局的 java 代码

private void setupUi() {

CardView cardView;
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

frameLayout = (FrameLayout) findViewById(R.id.container_pager_offer);
frameLayout.removeAllViews();

CardView.LayoutParams params;

int cardMargin = (int) getResources().getDimension(R.dimen.offer_card_overlapping);
int sideMargin = (int) getResources().getDimension(R.dimen.margin_semi_large);

for (int i = 0; i < 4; i++) {
cardView = (CardView) inflater.inflate(R.layout.card_offer_for_pager, null);
TextView textView = (TextView) cardView.findViewById(R.id.text_copy_code);
CommonUtils.setIconColor(textView, 2, R.color.label_header_opac);
params = new CardView.LayoutParams((int) getResources().getDimension(R.dimen.offer_card_width),
(int) getResources().getDimension(R.dimen.offer_card_height));
cardView.setX(cardMargin * ( 4 - i ) + sideMargin); //XCOORD
cardView.setY(cardMargin * ( i + 1 )); //YCOORD
cardView.setLayoutParams(params);
frameLayout.addView(cardView);
}
}

最佳答案

我已经找到了一个简单的答案,

请为 CardView 添加一个父布局,这个父布局可以是 LinearLayoutRelativeLayout,并为父布局提供透明背景,这样就可以了

下面是例子

<LinearLayout 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.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="@color/mdtp_circle_color"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true">
</android.support.v7.widget.CardView>
</LinearLayout >

关于android - CardView 阴影不显示,如果不止一张卡片相互重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39011972/

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