【发布时间】:2020-06-16 14:18:05
【问题描述】:
当我试图改变CardView的背景,或者它是覆盖CardView整个区域的孩子时,
高程阴影消失。
但是,当我使用app:contentPadding 属性时,海拔
阴影再次变得可见,但现在我在CardView 上有了这个奇怪的填充,这当然不是很好看。我发现,Material Design 的观点也存在这样的问题。
这是一个没有背景的MaterialToolbar,这是with 背景。下面是我的 XML 代码。
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
app:cardCornerRadius="8dp"
app:cardUseCompatPadding="true"
app:cardElevation="4dp"
>
<androidx.appcompat.widget.LinearLayoutCompat
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:background="@android:color/holo_green_dark"
>
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/news_image"
android:layout_width="match_parent"
android:layout_height="232dp"
/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/txt_news_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="@font/numans"
android:textSize="18sp"
android:textStyle="bold"
android:layout_margin="12dp"
android:textColor="@color/colorToolBarDarkSeaBlue"
/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/txt_news_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:layout_margin="12dp"
/>
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.cardview.widget.CardView>
这是 MaterialToolbar 的代码
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat
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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<com.google.android.material.appbar.MaterialToolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_margin="8dp"
android:elevation="8dp"
/>
</androidx.appcompat.widget.LinearLayoutCompat>
【问题讨论】:
标签: java android android-studio