android - 如何为某些子成员设置 cardview 的圆角半径?

标签 android android-layout android-cardview cornerradius

第一张图片是我的结果,我想让它看起来像第二张。我试图给出角半径,但它没有出现在屏幕上。我不知道是什么问题,而且父卡片 View 也没有显示海拔。

提前谢谢你。

enter image description here

enter image description here

<RelativeLayout 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"
    android:background="#ffffff"
    tools:context="com.software_solutions.optimus_tech_project201709.CourseSelect.CourseSelectionActivity">

    <Button
        android:id="@+id/register"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="Register" />


    <Button
        android:id="@+id/you"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:text="you" />

    <ImageView
        android:id="@+id/dialogImageView"
        android:layout_width="match_parent"
        android:layout_height="220dp"
        android:scaleType="fitXY"
        android:src="@drawable/dialog"
        android:text="Hello" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/dialogImageView"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="-180dp"
        android:gravity="center"
        android:orientation="vertical">

        <ImageView
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:src="@drawable/select_course" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:text="SELECT A COURSE"
            android:textColor="#ffffff"
            android:textSize="25dp"
            android:textStyle="bold" />
    </LinearLayout>

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="OK" />


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/dialogImageView"
        android:orientation="vertical"
        android:weightSum="2">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerViewSelectCourse"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="5dp" />


        <android.support.v7.widget.CardView
            android:id="@+id/cardViewDemo1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="10dp"
            android:layout_weight="1"
            android:elevation="3dp"
            app:cardCornerRadius="10dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="#e4a455"
                android:orientation="vertical"
                android:padding="10dp"
                android:weightSum="3">

                <android.support.v7.widget.CardView
                    android:id="@+id/cardViewDemo2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    app:cardCornerRadius="10dp">

                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:scaleType="fitXY"
                        android:src="@drawable/demo_one" />

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

                <android.support.v7.widget.CardView
                    android:id="@+id/cardViewDemo3"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_below="@id/cardViewDemo2"
                    android:layout_marginTop="5dp"
                    android:layout_weight="2"
                    app:cardCornerRadius="10dp">

                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:background="#e9cca8">

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerInParent="true"
                            android:text="DEMOVIDEOONE"
                            android:textColor="#fff"
                            android:textSize="15sp"
                            android:textStyle="bold" />

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


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

    </LinearLayout>

</RelativeLayout>

最佳答案

添加 app:cardBackgroundColor="#e9cca8" app:cardBackgroundColor="#e4a455" 并从您的 child RelativeLayout 和 LinearLayout 中移除背景

你有 3 个 CardView,在第 3 个 CardView 中,你只有 ImageView,所以最好不要使用 CardView,你可以使用圆角 ImageView 。

关于android - 如何为某些子成员设置 cardview 的圆角半径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44869675/

相关文章:

android - RecyclerView android 中的 ScrollView

android - 谷歌分析 android 的自动 Activity 跟踪如何工作

android - 读/写一个对象到文件

android - 如何以编程方式插入两个按钮?

android - 平板电脑和手机中抽屉导航的不同宽度

android - 如何在 RecyclerView 中的 CardView 上使用 OnClickListener?

android - layout_weight 不适用于 CardView

Android Studio 导出库\SDK 不暴露代码

android - 光标限制照片

文件后面的 Android 布局引用 xml 元素