如果有多个卡相互重叠,则不会显示CardView阴影

拉韦库什·阿格劳瓦尔(Lavekush Agrawal)

以下是参考/输出scrrenshot 在此处输入图片说明

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

更新:在下面,然后棒棒糖阴影正在工作

以下是其中的XML代码CardView,我以编程方式扩大了这些CardView布局,并设置XY属性以实现重叠视图

<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);
        }
}
拉韦库什·阿格劳瓦尔(Lavekush Agrawal)

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

请将父级布局添加到CardView,LinearLayout将此父级添加到CardView,并为父级RelativeLayout提供透明的背景,然后即可使用

以下是示例

<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 >

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如果有多个卡相互重叠,则不会显示CardView阴影

来自分类Dev

如果有某些项目,则不会添加android NavigationView子菜单

来自分类Dev

VB。如果有多个或内部

来自分类Dev

MySQL,如果有多个条件

来自分类Dev

PowerQuery 如果有多个条件 AND OR

来自分类Dev

如果有多个条件python

来自分类Dev

显示标题(如果有结果)

来自分类Dev

显示名称(如果有问题)

来自分类Dev

如果有任何更改,AngularJS 会同时重新加载多个选项卡

来自分类Dev

Shell脚本:如果有多个条件

来自分类Dev

数组的最小值(如果有多个结果)

来自分类Dev

如果有多个&&,|| Java中的条件评估

来自分类Dev

如果有多个条件无法解决

来自分类Dev

Shell脚本:如果有多个条件

来自分类Dev

如果有多个条件,则重定向

来自分类Dev

从多个表中删除(如果有)

来自分类Dev

Angular2 * ng如果有多个条件

来自分类Dev

如果有多个 .vimrc 将使用什么?

来自分类Dev

参数,如果有开关,则不允许其他参数

来自分类Dev

参数,如果有开关,则不允许其他参数

来自分类Dev

检查SD卡运行状况数据(如果有)

来自分类Dev

检查SD卡运行状况数据(如果有)

来自分类Dev

如果有选择的话

来自分类Dev

添加列(如果有)

来自分类Dev

VHDL如果有问题

来自分类Dev

存储值“如果有(”搜索

来自分类Dev

如果有计数则选择总和

来自分类Dev

功能:如果有中断,返回

来自分类Dev

如果有值则连接