我有两层布局,背景和内容(约束布局和图像):
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:background="@color/colorPrimary"
android:id="@+id/background_layout">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/content_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="150dp"
android:gravity="center_horizontal"
app:layout_constraintTop_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:elevation="20dp"
android:background="@color/backgroundColor">
<com.google.android.material.card.MaterialCardView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentTop="true"
android:translationY="50dp"
app:cardCornerRadius="50dp"
app:layout_constraintBottom_toTopOf="@+id/relativeLayout2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:elevation="21dp"
app:cardElevation="21dp">
<ImageView
android:id="@+id/circular_image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitCenter"
android:src="@mipmap/ic_launcher" />
</com.google.android.material.card.MaterialCardView>
</androidx.constraintlayout.widget.ConstraintLayout>
应该像image。当我在CardView中删除该行时
android:elevation="21dp"
预览says该图像在内容下,但在模拟器中没有任何变化...
[好,如果我们添加android:elevation并删除app:cardElevation图像将在模拟器中处于内容布局之下,而在预览中处于之上。
我的问题是怎么回事?
尝试添加:
android:clipToPadding="false"
在MaterialCardView中。