android - 添加圆角到约束布局会留下白色背景

标签 android android-drawable android-constraintlayout rounded-corners

我正在为我的设计使用约束布局。我是约束布局的新手。我的根布局是约束布局,我的子布局也是约束布局。我为我的根布局添加了带有圆角的背景,但它在拐角处留下了白色背景。下面是我的布局。此布局附加到 fragment 。

    <?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/background_black_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/res_bottomflat_topcorner_audiocontrols"
    app:layout_constraintBottom_toTopOf="@+id/background_grey_layout">


    <android.support.constraint.ConstraintLayout
        android:id="@+id/background_grey_layout"
        android:layout_width="0dp"
        android:layout_height="60dp"
        android:layout_marginStart="10dp"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:layout_marginEnd="10dp"
        android:background="@drawable/res_grey_roundfilled_corner"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/background_black_layout"
        app:layout_constraintBottom_toBottomOf="parent"
        >

        <android.support.v7.widget.CardView
            android:id="@+id/album_art_card_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:elevation="2dp"
            app:cardCornerRadius="8dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/background_grey_layout">

            <ImageView
                android:id="@+id/album_art"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:contentDescription="@string/currently_playing_song"
                android:scaleType="fitXY"
                tools:src="@drawable/ic_launcher" />

        </android.support.v7.widget.CardView>


        <LinearLayout
            android:id="@+id/content"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:orientation="vertical"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toEndOf="@+id/album_art_card_view"
            app:layout_constraintTop_toTopOf="@+id/background_grey_layout"
            app:layout_constraintEnd_toStartOf="@+id/favorite_layout"
            >

            <TextView
                android:id="@+id/title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:contentDescription="@string/currently_playing_song"
                android:ellipsize="end"
                android:fontFamily="@font/quicksand_medium"
                android:maxLines="1"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="@color/main_text"
                android:textSize="12sp"
                tools:text="The Best Music EVAH1111 THE BEST" />

            <TextView
                android:id="@+id/artist"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:contentDescription="@string/currently_playing_artist"
                android:ellipsize="end"
                android:fontFamily="@font/quicksand_regular"
                android:maxLines="1"
                android:text="A.R.Rehman"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="@color/sub_text"
                android:textSize="10sp" />

        </LinearLayout>

        <RelativeLayout
            android:id="@+id/favorite_layout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/play_pause"
            android:layout_marginEnd="20dp"
            app:layout_constraintTop_toTopOf="@+id/background_grey_layout"
            android:layout_marginStart="10dp">

            <CheckBox
                android:id="@+id/favorite"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:button="@null"
                android:clickable="false"
                android:drawableStart="@drawable/favourite_check_status"
                />
        </RelativeLayout>


        <ImageView
            android:id="@+id/play_pause"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:background="@drawable/bg_player_play_button_home"
            android:contentDescription="@string/play_pause"
            android:src="@drawable/ic_pause"
            android:layout_marginEnd="20dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="@+id/background_grey_layout"
            app:layout_constraintBottom_toBottomOf="parent"
            />
    </android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>

下面是我的可绘制文件。 res_bottomflat_topcorner_audiocontrols

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <!-- fill/color -->
    <solid
        android:color="#000000"/>
    <corners
        android:topLeftRadius="30dp"
        android:topRightRadius="30dp"
        />

</shape>

下面给出的图像是我得到的输出。

bottom control image

我需要的如下所示。

original output

我不知道我错过了什么。我搜索了很多,但没有找到与此相关的任何答案。需要帮忙。提前致谢。

最佳答案

您错过的是您必须将所需的背景颜色添加到 Root View 中 发生这种情况的另一个原因可能是您的回收器 View (假设您必须使用回收器)位于音乐播放 View 之上,它应该位于底部导航上方

关于android - 添加圆角到约束布局会留下白色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63007724/

相关文章:

android - 在具有四个单独字段的 Android 密码中,当使用 textwatcher 中的 requestfocus() 移动到下一个字段时,不会将前一个字段显示为点

android - 如何在 SQLite (Android) 中存储可绘制/位图

android - 无法在文本更改时调整项目组并尊重边距

android - 将资源(drawable)组织成Android Studio项目的一些疑惑

android - CircleCI 找不到 com.android.support.constraint :constraint-layout:1. 0.0-alpha3

android - 如何在ConstraintLayout 上设置三分之一的布局宽度百分比?

android - 在中国的 Android 可穿戴设备中获取 GPS 位置

android - Android 4.2.2 崩溃 : java. lang.RuntimeException : Failed to finish input event. status=-11

android - 扫描 NFC 标签时是否可以启动应用程序?

android - 如何在圆内画圆弧?