【发布时间】:2014-11-10 23:16:44
【问题描述】:
我在使用新的 CardView 时遇到了一些问题
这就是我目前的情况:我想使用 CardView 为所有设备(也包括 Pre-Lollipop)提供一个浮动操作按钮
我的活动布局如下所示
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cdcdcd"
android:focusable="false">
<include layout="@layout/toolbar"/>
<android.support.v7.widget.CardView
android:layout_width="58dp"
android:layout_height="58dp"
cardview:cardPreventCornerOverlap="true"
android:layout_gravity="bottom|right"
android:layout_marginBottom="16dp"
android:layout_marginRight="18dp"
cardview:cardCornerRadius="29dp"
cardview:cardBackgroundColor="?attr/colorPrimary">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_gravity="center"
android:layout_margin="12dp"
android:src="@android:drawable/ic_menu_edit"/>
</android.support.v7.widget.CardView>
在 Nexus 5 (4.4.4) 上运行应用程序,屏幕如下所示:
现在我想通过在 xml 中设置来设置 cardElevation
cardview:cardElevation="8dp"
启动应用后,按钮如下所示(不再是圆圈):
似乎设置卡片高度也会影响视图的尺寸...如果您现在仔细查看图片 #1,您会发现,此按钮也不是一个完美的圆形。
有没有办法解决这个问题?我也试过设置这个
cardview:cardPreventCornerOverlap="false"
但也没有影响
谢谢大家:)
【问题讨论】:
-
您为什么将 CardView 用于 FAB?
-
我使用 CardView 是因为我想在旧设备上提供阴影...
-
不要将 CardView 用于 FAB。它真的不是为此而设计的。
标签: android android-5.0-lollipop android-cardview