我正在尝试为应用程序的一些视图添加圆角和阴影,并利用卡片视图库来实现。在Lollipop设备上看起来不错,但在任何早于Lollipop的设备上都会遇到兼容性问题。
首先声明,我已经查看了下面问题中的答案,发现它们都不适用于我。
最流行的答案是添加属性'cardPreventOverlap=false',但这会删除圆角。我尝试了此标志和'cardUseCompatPadding="true"'的各种变化,但似乎都没有解决问题。还有人遇到过同样的问题吗?
我的代码:
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
card_view:cardCornerRadius="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/selector"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:layout_width="44dp"
android:layout_height="match_parent"
android:layout_marginRight="4dp"
android:background="@color/mid_yellow"
android:padding="0dp"
android:src="@drawable/ic_add_white_24dp" />
<TextView
style="@style/Text.Primary.White"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:text="Button" />
</LinearLayout>
这是在安卓5.0上的显示效果:
但在4.4.2版本上,同样的代码会显示为:
如果将 'cardPreventOverlap=false' 设置为 true,则显示效果为:
更新:很遗憾,我们无法解决这个问题;由于应用程序只有较少的安装基础,因此我们认为这不是很重要。最终,我们选择了第三个选项“cardPreventOverlap=false”。