小弟不知這方形是如何產生的,請大師解惑~
<?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="wrap_content">
<androidx.cardview.widget.CardView
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?android:attr/selectableItemBackground"
app:cardBackgroundColor="#80000000"
app:cardCornerRadius="15dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="centerCrop"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView"
android:layout_margin="10dp"
android:autoLink="email|web"
android:textColor="@color/colorWhite"
android:textSize="16sp" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="20dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/cardView"
tools:ignore="UselessLeaf">
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
更新:
將圓角去除就消失了,但還是希望有圓角,希望各位解答。
app:cardBackgroundColor="#80000000"//->透明度50%
app:cardBackgroundColor="#00000000"//->透明度0%
試著自定義一個Shape內容,名稱自訂->shape.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!--設定背景色-->
<solid android:color="#80000000"/>
<!--設定框線粗細和框線顏色-->
<stroke android:width="1dp" android:color="#80000000" />
</shape>
然後再套用其背景
app:cardBackgroundColor="shape.xml"