卡片式布局

Card looking Layout

我正在制作一个带有卡片状角的对话框。但我不能让它看起来像 card.I 可以转角,但仍然在对话框中显示红色半径颜色之上的部分。我尝试了一切,但我无法让它发挥作用。有人能帮我吗?我的主要布局是 cardView,我将形状布局放在线性布局的背景中。

<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF"/>
<stroke
    android:width="6dip"
    android:color="#f45"/>
<corners android:radius="15dip"/>
<padding
    android:bottom="0dip"
    android:left="0dip"
    android:right="0dp"
    android:top="0dip"/>

<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/layout_bg"
    >

    <TextView
        android:id="@+id/textView7"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="15dp"
        android:text="Bits Please"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:foreground="@android:color/transparent"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:layout_alignParentEnd="false"
        android:layout_alignParentStart="false"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_weight="1"
        android:background="#030202"
        android:orientation="horizontal">
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical">

        <TextView
            android:id="@+id/textView8"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:text="text"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:paddingBottom="10dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp">

        <TextView
            android:id="@+id/textView9"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
           />

        <TextView
            android:id="@+id/textView10"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
           />

        <TextView
            android:id="@+id/textView11"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="15dp"
          />
    </LinearLayout>
</LinearLayout>

将它与您的代码一起使用 -

dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

并在 cardview 中添加透明背景 -

<android.support.v7.widget.CardView
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 android:layout_width="250dp"
 android:layout_height="wrap_content"
 android:baselineAligned="false"
 android:orientation="vertical" 
 android:paddingLeft="10dp"
 android:paddingRight="10dp"
 android:background="@android:color/transparent" >

这对我没有任何作用,但是我只是将这行代码添加到 CardView 布局中。-> app:cardCornerRadius="amount"

不需要背景、主题、样式或任何东西。希望这对某人有帮助

和 activity 中的代码:

dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));