Полупрозрачный фон в CardView Не работает должным образом - PullRequest
0 голосов
/ 20 апреля 2020

У меня проблема с непрозрачностью фона CardView. Я хочу сделать свой фон полупрозрачным, но у меня есть странная ошибка, которая происходит постоянно. Лучшим объяснением будет скриншот из моей программы.

Scr из отображаемого макета

Я хочу, чтобы этот макет был одного и того же полупрозрачного цвета. Вместо этого появляется полупрозрачный цвет с более прозрачным прямоугольником внутри. Я не знаю, как удалить этот прямоугольник из моего макета. Код:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginBottom="5dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardCornerRadius="15dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        app:cardBackgroundColor="#66000000">


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layout_gravity="center">



                <androidx.cardview.widget.CardView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    app:cardCornerRadius="15dp">


                <ImageView
                    android:id="@+id/flagImageView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center"
                    android:adjustViewBounds="true"
                    android:fontFamily="@font/changa_light"
                    android:scaleType="fitXY"
                    app:srcCompat="@mipmap/ic_launcher" />
                </androidx.cardview.widget.CardView>

                <TextView
                    android:id="@+id/flagTextView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="TEST"
                    android:textColor="#ffffff"
                    android:gravity="center"
                    android:fontFamily="@font/changa_light"/>

            </LinearLayout>



    </androidx.cardview.widget.CardView>
    </LinearLayout>
</RelativeLayout>

Ответы [ 3 ]

0 голосов
/ 20 апреля 2020

Это то, что вы хотите?

<?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"
    android:layout_width="match_parent"
    android:layout_height="312dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="24dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="4dp"
    android:background="?attr/selectableItemBackground"
    android:clickable="true"
    android:focusable="true"
    android:foreground="?attr/selectableItemBackground"
    app:cardBackgroundColor="@color/sisman2"
    app:cardCornerRadius="20dp"
    app:cardElevation="2dp">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="8dp">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:ellipsize="end"
                android:gravity="center"
                android:singleLine="true"
                android:text="HELLO"
                android:textSize="24sp" />


        </RelativeLayout>


        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="248dp"
            android:elevation="0dp"
            app:cardCornerRadius="20dp"
            app:cardElevation="0dp">


        </androidx.cardview.widget.CardView>

    </RelativeLayout>

</androidx.cardview.widget.CardView>
0 голосов
/ 20 апреля 2020

заключают первый объект cardView в макет фрейма, затем увеличивают его и держат наверху (помните! Elevation> = API 21)

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:background="@color/transparentColor"
            android:elevation="3dp"
            android:stateListAnimator="@null">
           <!-- into-->

        </FrameLayout>
0 голосов
/ 20 апреля 2020

РЕШИТЬ! Мне пришлось добавить app:cardElevation="0dp к первому CardView

...