简体   繁体   English

cardview 不显示cornerRadius 和高程

[英]cardview not showing cornerRadius and elevation

I created a card view in a recycler view and my codes work well but the problem now is that the cardview does not show the rounded edges and elevation at runtime but it shows in the design codes.我在回收站视图中创建了一个卡片视图,我的代码运行良好,但现在的问题是卡片视图在运行时不显示圆角边缘和高程,但它显示在设计代码中。 my codes are shown blow我的代码显示为打击

activity_main活动主

<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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Controller.MainActivity">

    <uk.co.markormesher.android_fab.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:buttonIcon="@drawable/ic_add_group"
        />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/groupListView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

my card_view.xml我的card_view.xml

<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:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.v7.widget.CardView
    android:id="@+id/groupCardView"
    android:layout_width="match_parent"
    android:layout_height="128dp"
    android:layout_marginEnd="16dp"
    android:layout_marginStart="16dp"
    android:layout_marginTop="24dp"
    app:cardCornerRadius="10dp"
    app:cardElevation="5dp"
    app:cardUseCompatPadding="true"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent">

        <TextView
            android:id="@+id/groupTitle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:text="Trips"
            android:textAlignment="center"
            android:textSize="30sp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />
    </android.support.constraint.ConstraintLayout>
</android.support.v7.widget.CardView>

I do not know what I have done wrong我不知道我做错了什么

Anyone could encounter this issue and the solution is very simple and caused by a mistake.there's a difference between backgroundColor and cardbackgroundColor .任何人都可能遇到这个问题,解决方法很简单,是由错误引起的。 backgroundColorcardbackgroundColor之间存在差异。 use setcardbackgroundColor and it should work.使用setcardbackgroundColor它应该可以工作。

You need to set你需要设置

android:background="@android:color/transparent"

for main constraint, and set对于主要约束,并设置

app:cardBackgroundColor="@color/white"

to cardview, np到cardview,np

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM