Android 使用CardView小部件在一行中显示多列

Android 使用CardView小部件在一行中显示多列,android,Android,我在一行中实现了两列,如下所示。然而,我最近才知道有一个卡片视图小部件,它让我感觉更好。但我想知道怎么可能在一行中有两列? 如果可能的话,您建议我从网格视图切换到卡片视图吗?现在常用吗 <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/swiperefresh"

我在一行中实现了两列,如下所示。然而,我最近才知道有一个卡片视图小部件,它让我感觉更好。但我想知道怎么可能在一行中有两列? 如果可能的话,您建议我从网格视图切换到卡片视图吗?现在常用吗

<android.support.v4.widget.SwipeRefreshLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/swiperefresh"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <GridView
            android:id="@+id/gridview"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:verticalSpacing="2dp"
            android:horizontalSpacing="2dp"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            android:paddingBottom="@dimen/activity_vertical_margin"
            android:stretchMode="columnWidth"
            android:numColumns="2"/>

</android.support.v4.widget.SwipeRefreshLayout>

以下xml在一行中生成两列是否正确

<LinearLayout 
            android:layout_width="match_parent" 
            android:layout_height="wrap_content"
            android:orientation="horizontal">
        <android.support.v7.widget.CardView
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content">
        </android.support.v7.widget.CardView>
        <android.support.v7.widget.CardView
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content">
        </android.support.v7.widget.CardView>
</LinearLayout>

我建议您使用Recyclerview和cardview。Gridview是一个古老的视图,谷歌很快就会反对它。Recyclerview比gridview好

您不必在Gridview的一行中添加两列。相反,您可以使用Recyclerview来获得更好的效果。Cardview只是视图的列表项背景。 -只需设计与您的设计相对应的列表项 -将其添加到RecycleServiceAdaper中 -将此与RecyclerView连接 -把它修好

下面是一个在卡片视图中使用网格项的recyclerview示例


下面是一个使用该
回收视图的好例子:

只需在此布局中使用
cardwiew

List_row.xml

大概是这样的:

<android.support.v7.widget.CardView
    android:id="@+id/card_view"
    android:background="@color/white"
    android:layout_width="200dp"
    android:layout_height="200dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <TextView
            android:id="@+id/info_text"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Textview one"
            android:gravity="center"
            android:textSize="36sp" />
        <TextView
            android:id="@+id/info_text1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Textview two"
            android:gravity="center"
            android:textSize="36sp" />
    </LinearLayout>

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


不建议使用
GridView
RecyclerView
已经有
GridLayoutManager

是否可以提供示例代码或任何教程链接?示例代码用于回收器视图以及一行中两列的卡片视图。伙计,很抱歉我上传的源代码太晚了。现在检查一下代码。谢谢你的帮助。