【问题标题】:Android Material CardView with HorizontalScrollView带有 Horizo​​ntalScrollView 的 Android 材质 CardView
【发布时间】:2015-07-14 04:42:03
【问题描述】:

我需要在HorizontalScrollView 中显示CardViews,如下面的教程 http://examples.javacodegeeks.com/android/core/ui/horizontalscrollview/android-horizontalscrollview-example/

这是我尝试过的:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:weightSum="3">

    <HorizontalScrollView
        android:id="@+id/horizontalScrollView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="50dp">

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <android.support.v7.widget.CardView
                android:id="@+id/view2"
                android:layout_width="170dp"
                android:layout_height="220dp"
                android:layout_alignParentEnd="true"
                android:layout_alignTop="@+id/horizontalScrollView"
                android:clickable="true"
                android:foreground="?android:attr/selectableItemBackground"
                card_view:cardCornerRadius="3dp"
                card_view:cardElevation="3sp"
                card_view:cardUseCompatPadding="true" />
        </RelativeLayout>
    </HorizontalScrollView>

    <android.support.v7.widget.CardView
        android:id="@+id/view5"
        android:layout_width="170dp"
        android:layout_height="220dp"
        android:clickable="true"
        android:foreground="?android:attr/selectableItemBackground"
        card_view:cardCornerRadius="3dp"
        card_view:cardElevation="3sp"
        card_view:cardUseCompatPadding="true"
        android:layout_alignTop="@+id/horizontalScrollView"
        android:layout_alignParentEnd="true"
        android:layout_marginEnd="33dp" />


</RelativeLayout>

但是我不能在这个布局中使用两个以上的卡片视图。(inHorizontalScrollView)

我应该为这个 porpose 使用另一个小部件还是如果我需要在这个 Horizo​​ntal ScrollView 中显示 5 个 CardView 有什么问题?

干杯!

【问题讨论】:

    标签: android scrollview android-cardview


    【解决方案1】:

    您可以使用 android 支持库中的RecyclerView,您可以查看如何将其添加到您的项目here。这是一个更好的列表视图实现,它带有一个布局管理器,您可以通过它将其配置为Horizontalvertical 滚动模式

    mRecyclerLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    

    【讨论】:

    • 谢谢。所以这意味着我们不能使用HorizontalScrollView 来处理这个海豚?有没有关于这个设计的图或例子?
    • @AndroidDev 这里是demo 用于使用回收站视图。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-18
    • 2014-02-13
    相关资源
    最近更新 更多