我们可以在Android Studio的相对布局中使用cardView吗?

我们可以在Android Studio的相对布局中使用cardView吗?,android,android-studio,android-cardview,Android,Android Studio,Android Cardview,我在相对布局中使用了一个简单的卡片视图。 我可以在相对布局中使用它吗?如果是,则如何使用?如果您在RelativeLayout中使用CardView,如下所示: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:background="@android:color/black" android:layou

我在相对布局中使用了一个简单的卡片视图。
我可以在相对布局中使用它吗?如果是,则如何使用?

如果您在RelativeLayout中使用CardView,如下所示:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="@android:color/black"
android:layout_height="match_parent">

    <android.support.v7.widget.CardView
    ....>
        <....>//Imagine a TextView here 
        <....>
    </android.support.v7.widget.CardView>
</RelativeLayout>

//想象一下这里有一个文本视图
然后,您将无法以正确的方式在cardview中排列元素

简言之,将CardView想象为一个支架,您必须使用CardView内部的布局才能使其以正确的方式工作

例如:

<android.support.v7.widget.CardView
    ....>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:background="@android:color/black"
    android:layout_height="match_parent">
            <....>//Imagine a TextView here 
            <....>
    </RelativeLayout>
 </android.support.v7.widget.CardView>

//想象一下这里有一个文本视图

是的,我们可以使用,请按照代码操作:

 <!-- About Panel -->
<android.support.v7.widget.CardView
    android:id="@+id/cv_About"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/cv_Help"
    android:layout_gravity="center"
    android:elevation="3dp"
    app:cardCornerRadius="0dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="@dimen/pad_20dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:text="@string/about"
            android:textColor="@color/dimblack"
            android:id="@+id/tvAbout"
            />

    </RelativeLayout>

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


干杯

嗯,把它放在一个
RelativeLayout
中。你到底在问什么?CardView只是一个视图组。可以像在任何其他视图组中使用普通视图组一样使用它。