对话框,设置阴影

时间:2019-04-19 09:11:47

标签: android android-layout

我正在为一个项目编写应用程序。我的问题是如何在第一和第二约束布局之间设置阴影?  我是否需要在drawabale中创建xml以添加到主要的XML中?

我在下面发布了xml,并且如果有必要也放置Java代码。

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:id="@+id/constraintLayout"
        android:layout_width="350dp"
        android:layout_height="310dp"
        android:background="#ff6600">

        <android.support.constraint.ConstraintLayout
            android:layout_width="290dp"
            android:layout_height="266dp"
            android:background="#f2f2f2"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.266"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.491">

            <TextView
                android:id="@+id/textView"
                android:layout_width="212dp"
                android:layout_height="157dp"
                android:layout_marginStart="8dp"
                android:layout_marginTop="16dp"
                android:layout_marginEnd="8dp"
                android:layout_marginBottom="8dp"
                android:gravity="center"
                android:text="Vuoi registrarti al Torneo?"
                android:textAlignment="center"
                android:textColor="#000"
                android:textSize="20dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.105" />

            <Button
                android:id="@+id/Btn_yes"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="8dp"
                android:layout_marginBottom="8dp"
                android:text="SI"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toStartOf="@+id/Btn_No"
                app:layout_constraintHorizontal_bias="0.508"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/textView"
                app:layout_constraintVertical_bias="0.512" />

            <Button
                android:id="@+id/Btn_No"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="8dp"
                android:layout_marginBottom="8dp"
                android:text="NO"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.845"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/textView"
                app:layout_constraintVertical_bias="0.512" />
        </android.support.constraint.ConstraintLayout>
    </android.support.constraint.ConstraintLayout>

感谢您的回答。

1 个答案:

答案 0 :(得分:1)

您可以像这样使用Cardview:

app:cardUseCompactPadding =“ true”

还要在清单文件中提及 android:hardwareAccelerated =“ true”

<android.support.v7.widget.CardView
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginRight="5dp"
        app:cardBackgroundColor="@color/colorprimary"
        app:cardCornerRadius="5dp"
        app:cardUseCompatPadding="true"
        app:elevation="0dp">
    </android.support.v7.widget.CardView>