如何实现固定项目的MainActivity卡片视图菜单?

How to implement MainActivity card view menu with fixed items?

我应该使用什么来实现 4 个固定项目菜单,用户将从中转到下一个 activity?这 4 个卡片视图应该大小相同,并且无需滚动即可看到。

我想用card view,但是不知道是放RecyclerView还是单独做4个card view

感谢帮助

如果cardviews的数量只有4个并且是固定的那么就不需要recyclerview了。将它们一个放在另一个下面。使用 LinearLayout 并将其方向设置为垂直。将所有卡片视图放入此 LinearLayout 中。

然后您可以在每个 CardView 上分别设置 onClick 侦听器,以将您带到所需的 Activity。

这里是使用 cardview 修复的四个布局。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical">

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_weight="1"
    android:layout_height="match_parent">

    <LinearLayout android:layout_width="match_parent"
                  android:layout_height="match_parent">

        <ImageView
            android:layout_width="50dp"
            android:layout_height="match_parent"
            android:src="@drawable/ic_launcher"

            />

        <TextView android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:text="dsafdaf"/>

    </LinearLayout>

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

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_weight="1"
    android:layout_height="match_parent">

    <LinearLayout android:layout_width="match_parent"
                  android:layout_height="match_parent">

        <ImageView
            android:layout_width="50dp"
            android:layout_height="match_parent"
            android:src="@drawable/ic_launcher"

            />

        <TextView android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:text="dsafdaf"/>

    </LinearLayout>

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

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_weight="1"
    android:layout_height="match_parent">

    <LinearLayout android:layout_width="match_parent"
                  android:layout_height="match_parent">

        <ImageView
            android:layout_width="50dp"
            android:layout_height="match_parent"
            android:src="@drawable/ic_launcher"

            />

        <TextView android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:text="dsafdaf"/>

    </LinearLayout>

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

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_weight="1"
    android:layout_height="match_parent">

    <LinearLayout android:layout_width="match_parent"
                  android:layout_height="match_parent">

        <ImageView
            android:layout_width="50dp"
            android:layout_height="match_parent"
            android:src="@drawable/ic_launcher"

            />

        <TextView android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:text="dsafdaf"/>

    </LinearLayout>

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

</LinearLayout>