Android CardView使用问题记录

来源:互联网 发布:软件报价怎么描述 编辑:程序博客网 时间:2024/05/24 05:37

这里写图片描述

问题一:明明在cardview中设置了圆角,为啥xml视图上面还是直角,最开始用cardview时候会有这东西设置无效的错觉,这个问题直接运行到真机上面看就可以了。

这里写图片描述

问题二:明明我给carcview设置了背景色,为啥展示是白色的,而且运行到真机上面也是白色的。 Carview设置背景颜色有其自己的属性:app:cardBackgroundColor=”#FE5C93”。

这里写图片描述

问题三:明明我给carcview设置了elevation属性

这里写图片描述

为啥当下面view也设置elevation的时候,上面的效果消失了? 解决:把两个view同时设置为cardview,那么两个view为同以层次,要么给两个view中间设置点间距,让阴影展示出来,要么把层次划分清楚。下面是代码:

<android.support.v7.widget.CardView            android:layout_width="match_parent"            android:layout_height="0dp"            app:layout_heightPercent="30%w"            app:cardCornerRadius="0dp"            android:elevation="@dimen/carview_elevation">            <com.zhy.android.percent.support.PercentLinearLayout                android:layout_width="match_parent"                android:layout_height="match_parent"                android:orientation="vertical">                <android.support.v7.widget.CardView                    android:layout_width="match_parent"                    android:layout_height="0dp"                    app:layout_heightPercent="15%w"                    app:cardCornerRadius="0dp"                    android:elevation="@dimen/carview_elevation">                    <com.zhy.android.percent.support.PercentRelativeLayout                        android:layout_width="match_parent"                        android:layout_height="wrap_content">                        <TextView                            android:layout_width="match_parent"                            android:layout_height="match_parent"                            android:background="@color/main_top_red"                            app:layout_textSizePercent="35%"                            android:textColor="@color/white"                            android:text="目的地"                            android:gravity="center"/>                        <ImageView                            android:layout_width="0dp"                            app:layout_widthPercent="40%h"                            android:layout_height="match_parent"                            android:src="@mipmap/search_white"                            android:layout_alignParentRight="true"                            android:layout_centerVertical="true"                            app:layout_marginRightPercent="5%w"/>                    </com.zhy.android.percent.support.PercentRelativeLayout>                </android.support.v7.widget.CardView>                <com.zhy.android.percent.support.PercentRelativeLayout                    android:layout_width="match_parent"                    android:layout_height="match_parent">                    <TextView                        android:layout_width="match_parent"                        android:layout_height="match_parent"                        android:textColor="@color/black"                        app:layout_textSizePercent="25%"                        android:text="美国"                        android:gravity="center_vertical"                        app:layout_marginLeftPercent="5%w"                        android:background="@color/white"/>                </com.zhy.android.percent.support.PercentRelativeLayout>            </com.zhy.android.percent.support.PercentLinearLayout>        </android.support.v7.widget.CardView>

效果:

这里写图片描述

程序员趣闻

推荐下本人的微信公众号,本博客及其他方面的消息会定期同步到公众号上面!

0 0
原创粉丝点击