【发布时间】:2017-06-07 09:15:05
【问题描述】:
我有一个简单的 CardView 布局
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/cv_tag"
android:layout_width="wrap_content"
android:layout_height="@dimen/tag_height"
android:layout_margin="4dp"
android:clickable="true"
app:cardCornerRadius="20dp"
app:cardElevation="2dp">
<FrameLayout
android:id="@+id/fl_selection_indicator"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv_tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="8dp"
android:textAppearance="@style/PrimaryWhiteText.Tiny"
tools:text="Hard"/>
</FrameLayout>
</android.support.v7.widget.CardView>
而且它的渲染效果并不像我期望的那样。看起来系统将此布局包装到具有高程和白色背景的 FrameLayout 中。有趣的是,如果我自己将此布局包装到 FrameLayout 中,海拔会消失但白色背景仍然存在(框架布局的背景不是 CardView)
如何去除高程和白色背景,为什么会这样?
提前致谢!
【问题讨论】:
-
你确实有海拔
app:cardElevation="2dp" -
前段时间我也面临同样的问题。在我的情况下,由于 android:hardwareAccelerated="false" 这个属性在清单文件中
-
希望对您有所帮助....stackoverflow.com/questions/44407057/…
-
@IvBaranov 这是卡片的高度,应该只影响卡片视图(彩色部分)而不影响其背景(白色部分)
-
@PankajSharma 这个属性在清单中删除了海拔但在所有视图上((所以它不起作用
标签: android view background android-cardview elevation