Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
低android版本上的CardView设计问题_Android_Android Button_Android Cardview - Fatal编程技术网

低android版本上的CardView设计问题

低android版本上的CardView设计问题,android,android-button,android-cardview,Android,Android Button,Android Cardview,当我使用“CardView”创建圆角按钮时,我面临一个奇怪的问题。让我向你解释一下我面临的设计问题。下面是用来制作圆角按钮的代码: <androidx.cardview.widget.CardView android:id="@+id/tv_email_next" android:layout_width="match_parent" android:layout_height="wrap_content"

当我使用“CardView”创建圆角按钮时,我面临一个奇怪的问题。让我向你解释一下我面临的设计问题。下面是用来制作圆角按钮的代码:

<androidx.cardview.widget.CardView
    android:id="@+id/tv_email_next"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/tv_error_message"
    android:layout_marginStart="20dp"
    android:layout_marginEnd="20dp"
    android:layout_marginTop="20dp"
    app:cardBackgroundColor="#f15b5d"
    app:cardCornerRadius="34dp"
    app:cardElevation="5dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/submit_btn_bg">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:text="@string/next"
            android:textSize="16sp"
            android:textColor="@android:color/white"
            android:textStyle="bold"
            android:layout_centerVertical="true"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"/>

    </RelativeLayout>

</androidx.cardview.widget.CardView>

但当我在Android 10中运行相同的代码时,它看起来就像这样:


我不认为这种行为在Cardview中。有人知道我是如何解决这个问题的吗?

这是因为您应该在半径中输入cardViews高度dp的一半。如果您的cardview的高度为50dp,请将25 dp作为半径放入
submit\u btn\u bg


我还建议您使用button,因为它比使用cardview as按钮要好得多。

这是上面按钮的更好表示,输出与您的非常相似,代码更少

<com.google.android.material.button.MaterialButton
    android:id="@+id/button"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="32dp"
    android:layout_marginEnd="32dp"
    android:backgroundTint="#F44336"
    android:padding="8dp"
    android:text="Next"
    android:textAllCaps="false"
    android:textColor="@android:color/white"
    android:textSize="16sp"
    android:theme="@style/Theme.MaterialComponents"
    app:cornerRadius="20dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

输出:

兄弟,别忘了投票赞成或检查这个答案。这样你的问题就不会堆积在提要中了。没有理由使用CardView和TextView来实现圆角按钮。只需使用MaterialButton。使用
app:backgroundTint
而不是
android:backgroundTint
<com.google.android.material.button.MaterialButton
    android:id="@+id/button"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="32dp"
    android:layout_marginEnd="32dp"
    android:backgroundTint="#F44336"
    android:padding="8dp"
    android:text="Next"
    android:textAllCaps="false"
    android:textColor="@android:color/white"
    android:textSize="16sp"
    android:theme="@style/Theme.MaterialComponents"
    app:cornerRadius="20dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />