0

我正在尝试制作具有圆形左下角和右下角的布局,但没有一个解决方案对我有用。我尝试了各种方法,例如:

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

    <solid android:color="@android:color/white"/>
    <padding android:right="0dp"
        android:top="0dp"
        android:bottom="0dp"
        android:left="0dp"/>

    <corner
        android:topLeftRadius="0.1dp"
        android:topRightRadius="0.1dp"
        android:bottomLeftRadius="10dp"
        android:bottomRightRadius="10dp" />
</shape>

main_activity.xml:

<?xml version="1.0" encoding="utf-8"?>
<layout 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">

    <data>

        <import type="android.view.View" />

        <variable
            name="viewModel"
            type="com.abc.mvModel" />
    </data>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@android:color/transparent"
        tools:context=".home.HomeActivity">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/bottom_rounded"/>

            <LinearLayout
                android:id="@+id/taskBar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/bottom_rounded"
                android:orientation="horizontal">

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:paddingTop="5dp"
                    android:paddingLeft="20dp"
                    android:layout_weight="1.7">

                    <ImageView
                        android:layout_width="143dp"
                        android:layout_height="56dp"
                        android:layout_gravity="left|center_vertical"
                        android:layout_marginBottom="5dp"
                        android:src="@drawable/logo" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="3"
                    android:gravity="center"
                    android:orientation="horizontal">

                    <LinearLayout
                        android:id="@+id/learn"
                        android:visibility="gone"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center_horizontal"
                        android:orientation="vertical">

                        <ImageView
                            android:layout_width="33dp"
                            android:layout_height="30dp"
                            android:layout_gravity="center_vertical"
                            android:src="@drawable/learn_icon" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:layout_marginTop="5dp"
                            android:text="@string/learn"
                            android:textColor="@color/lineColor"
                            android:textSize="11sp" />

                        <View
                            android:id="@+id/learn_bar"
                            android:layout_width="match_parent"
                            android:layout_height="2dp"
                            android:layout_marginTop="5dp"
                            android:background="@color/lineColor" />

                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/practice"
                        android:visibility="gone"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="50dp"
                        android:gravity="center_horizontal"
                        android:orientation="vertical">

                        <ImageView
                            android:layout_width="42dp"
                            android:layout_height="28dp"
                            android:src="@drawable/practice_icon" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:layout_marginTop="5dp"
                            android:text="@string/practice"
                            android:textColor="@color/lineColor"
                            android:textSize="11sp" />

                        <View
                            android:id="@+id/practice_bar"
                            android:layout_width="match_parent"
                            android:layout_height="2dp"
                            android:layout_marginTop="5dp"
                            android:background="@color/lineColor"
                            android:visibility="gone" />

                    </LinearLayout>

                </LinearLayout>

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_marginRight="20dp"
                    android:layout_weight="1.3"
                    android:gravity="right"
                    android:orientation="horizontal">

                    <LinearLayout
                        android:id="@+id/unlock"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center_horizontal"
                        android:orientation="vertical">

                        <ImageView
                            android:layout_width="26.5dp"
                            android:layout_height="32dp"
                            android:src="@drawable/unlock_blue" />

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:layout_marginTop="5dp"
                            android:text="@string/unlock"
                            android:textColor="@color/lineColor"
                            android:textSize="11dp" />

                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/language"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="20dp"
                        android:gravity="center_horizontal|bottom"
                        android:orientation="vertical">

                        <ImageView
                            android:layout_width="33dp"
                            android:layout_height="30dp"
                            android:layout_marginTop="2dp"
                            android:src="@drawable/language" />

                        <TextView
                            android:id="@+id/language_title"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_horizontal"
                            android:layout_marginTop="5dp"
                            android:text="@string/lang"
                            android:textColor="@color/lineColor"
                            android:textSize="11dp" />

                    </LinearLayout>

                </LinearLayout>

            </LinearLayout>

        <LinearLayout
            android:id="@+id/appbar_practice"
            android:visibility="gone"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorPrimaryDark"
            android:gravity="center_horizontal"
            android:orientation="horizontal"
            android:paddingTop="@dimen/_10sdp">

            <LinearLayout
                android:id="@+id/read_mode"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <ImageView
                        android:layout_width="@dimen/_12sdp"
                        android:layout_height="@dimen/_12sdp"
                        android:background="@drawable/icon_read" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="@dimen/_5sdp"
                        android:fontFamily="@font/nunito_semibold"
                        android:text="@string/read"
                        android:textAllCaps="true"
                        android:textColor="@android:color/white"
                        android:textSize="@dimen/_7ssp" />

                </LinearLayout>

                <View
                    android:id="@+id/read_bar"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/_1sdp"
                    android:layout_marginTop="@dimen/_10sdp"
                    android:background="@android:color/white" />

            </LinearLayout>

            <LinearLayout
            android:id="@+id/speak_mode"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/_30sdp"
            android:orientation="vertical">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <ImageView
                    android:layout_width="@dimen/_12sdp"
                    android:layout_height="@dimen/_12sdp"
                    android:background="@drawable/icon_speak" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="@dimen/_5sdp"
                    android:fontFamily="@font/nunito_semibold"
                    android:text="@string/speak"
                    android:textAllCaps="true"
                    android:textColor="@android:color/white"
                    android:textSize="@dimen/_7ssp" />

            </LinearLayout>

            <View
                android:id="@+id/speak_bar"
                android:layout_width="match_parent"
                android:layout_height="@dimen/_1sdp"
                android:layout_marginTop="@dimen/_10sdp"
                android:background="@android:color/white"
                android:visibility="gone" />

        </LinearLayout>

            <LinearLayout
                android:id="@+id/listen_mode"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/_30sdp"
                android:orientation="vertical">

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <ImageView
                        android:layout_width="@dimen/_12sdp"
                        android:layout_height="@dimen/_12sdp"
                        android:background="@drawable/icon_listen" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="@dimen/_5sdp"
                        android:fontFamily="@font/nunito_semibold"
                        android:text="@string/listen"
                        android:textAllCaps="true"
                        android:textColor="@android:color/white"
                        android:textSize="@dimen/_7ssp" />

                </LinearLayout>

                <View
                    android:id="@+id/listen_bar"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/_1sdp"
                    android:layout_marginTop="@dimen/_10sdp"
                    android:background="@android:color/white"
                    android:visibility="gone" />

            </LinearLayout>

            <LinearLayout
                android:id="@+id/write_mode"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/_30sdp"
                android:orientation="vertical">

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <ImageView
                        android:layout_width="@dimen/_12sdp"
                        android:layout_height="@dimen/_12sdp"
                        android:background="@drawable/icon_write" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="@dimen/_5sdp"
                        android:fontFamily="@font/nunito_semibold"
                        android:text="@string/write"
                        android:textAllCaps="true"
                        android:textColor="@android:color/white"
                        android:textSize="@dimen/_7ssp" />

                </LinearLayout>

                <View
                    android:id="@+id/write_bar"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/_1sdp"
                    android:layout_marginTop="@dimen/_10sdp"
                    android:background="@android:color/white"
                    android:visibility="gone" />

            </LinearLayout>

        </LinearLayout>

        <FrameLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </LinearLayout>

</layout>

但它不起作用,我也尝试过使用 CardView 但它只适用于所有角落。所以请帮帮我。

编辑:我也添加了 Activity.xml 代码。

4

1 回答 1

1

您可以使用带有圆底角的MaterialShapeDrawable应用 a 。 就像是:ShapeAppearanceModel

    val radius = resources.getDimension(R.dimen.cornerSize16)

    val linearLayout = findViewById<LinearLayout>(R.id.layout)
    val shapeAppearanceModel = ShapeAppearanceModel()
        .toBuilder()
        .setBottomLeftCorner(CornerFamily.ROUNDED, radius)
        .setBottomRightCorner(CornerFamily.ROUNDED, radius)
        .build()

    val shapeDrawable = MaterialShapeDrawable(shapeAppearanceModel)
    shapeDrawable.fillColor = ContextCompat.getColorStateList(this, R.color....)
    ViewCompat.setBackground(linearLayout, shapeDrawable)

在此处输入图像描述

于 2020-09-30T14:38:28.987 回答