如何创建水平可滚动CardView [英] how to create Horizontal scroll-able CardView

查看:87
本文介绍了如何创建水平可滚动CardView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试如下创建页面,

Hi I am try to create a page as below,

我有一个抽屉布局,并且要在主屏幕中像在屏幕截图中一样显示通知.我正在尝试通过CardView进行此操作,但是我没有任何教程说明如何在CardView中实现此目标.我在listView中找到了Cardview的教程,但不是我的要求.有人可以告诉我如何实现这一目标吗?我在android中有什么可能的选择?

I have a drawer layout and in the home screen I want to display notifications as in the screen shot. I am trying to do it by CardView but I didn't got any tutorial explaining how I can achieve this in CardView. I got tutorials for Cardview in the listView but not for my requirement. Can anybody tell me how I can achieve this?. What all the possible options I have for this in android?

推荐答案

在android和Cardview中搜索RecyclerView.下面的示例仅用于说明如何像添加的图片一样进行创建.要添加CardViewn编号,请阅读如何在android中使用RecyclerView".

Search for RecyclerView in android, and Cardview. The below example is just a purpose to show how to create like the pic you added. To add n numbers of CardView read "How to use RecyclerView in android".

        <HorizontalScrollView
        android:layout_width="your_size"
        android:layout_height="your_size"
        android:id="@+id/horizontalScrollView"
        android:layout_below="@+id/your_id"
        android:scrollbars="none">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:padding="2dp">

            <android.support.v7.widget.CardView
                android:layout_width="250dp"
                android:layout_height="match_parent"
                android:layout_marginStart="2dp"
                android:padding="2dp"
                android:id="@+id/cardThree"
                android:layout_toEndOf="@+id/cardTwo"
                android:background="@color/card_color">

                //your view here like a Layout including textView.

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

            <android.support.v7.widget.CardView
                android:layout_width="250dp"
                android:layout_height="match_parent"
                android:padding="2dp"
                android:id="@+id/cardOne"
                android:background="@color/card_color">

                <//your view here like a Layout including textView.

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

            <android.support.v7.widget.CardView
                android:layout_width="250dp"
                android:layout_height="match_parent"
                android:layout_marginStart="2dp"
                android:padding="2dp"
                android:id="@+id/cardTwo"
                android:layout_toEndOf="@+id/cardOne"
                android:background="@color/card_color">

                //your view here like a Layout including textView.

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

这篇关于如何创建水平可滚动CardView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆