iT邦幫忙

0

[已解決]AndroidStudio更改背景透明度但會有方形痕跡

小弟不知這方形是如何產生的,請大師解惑~

<?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>

更新:
將圓角去除就消失了,但還是希望有圓角,希望各位解答。

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
ant1017
iT邦新手 2 級 ‧ 2020-07-14 14:57:32
app:cardBackgroundColor="#80000000"//->透明度50%
app:cardBackgroundColor="#00000000"//->透明度0%

想了解計算方式可以參考: https://blog.csdn.net/hewuzhao/article/details/78821954

試著自定義一個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"

我是指中間方框不同色調的問題

ant1017 iT邦新手 2 級 ‧ 2020-07-15 08:40:05 檢舉

已更新內容。

我要發表回答

立即登入回答