Тень не отображается на Androidx Cardview - PullRequest
0 голосов
/ 13 мая 2019

Мой файл макета:

<?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"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    tools:context=".TurnOnLocation">

    <LinearLayout
        android:id="@+id/requires_location"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toTopOf="@id/turn_on_location">
        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            card_view:cardCornerRadius="4dp"
            app:cardElevation="10dp"
            app:cardPreventCornerOverlap="false">
            <TextView
                android:id="@+id/info_text"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingTop="10dp"
                android:paddingBottom="10dp"
                android:paddingStart="60dp"
                android:paddingEnd="60dp"
                android:textSize="28sp"
                android:text="test"
                android:textColor="@color/colorPrimary"
                android:textAlignment="center"
                android:background="@color/colorPrimaryDark" />

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

    <androidx.appcompat.widget.AppCompatButton
        android:id="@+id/turn_on_location"
        android:textColor="@color/colorPrimary"
        android:textSize="@dimen/medium_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/turn_on_location"
        app:layout_constraintTop_toBottomOf="@id/requires_location"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

Я указал app:cardElevation="10dp", который, как мне кажется, предназначен для рендеринга тени.Однако никакой тени не появляется.

Есть идеи почему?

Ответы [ 4 ]

1 голос
/ 13 мая 2019

Вы не ошиблись в своем исходном коде.Тень должна быть правильно отображена.Вы можете проверить вывод в предварительном просмотре макета.Это имеет некоторые проблемы при рендеринге.Пожалуйста, запустите приложение в эмуляторе или на реальном устройстве.

0 голосов
/ 13 мая 2019

Попробуйте это

<androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        card_view:cardCornerRadius="4dp"
        app:cardElevation="10dp"
        android:layout_margin="16dp">
</androidx.cardview.widget.CardView
0 голосов
/ 13 мая 2019

Добавьте эту строку в ваш AndroidManifest этот android:hardwareAccelerated="true" в application тег

0 голосов
/ 13 мая 2019

добавить строки ниже в тег CardView

  card_view:cardBackgroundColor="@android:color/white"
  card_view:cardElevation="2dp"
  card_view:cardUseCompatPadding="true"
...