【问题标题】:How to make two cardview scrolling horizontally?如何让两个cardview水平滚动?
【发布时间】:2017-12-05 19:52:35
【问题描述】:

我有两个具有不同子视图的卡片视图,我希望它们显示在我的屏幕底部并希望它们水平滚动,我已阅读其他文档。但它们都不适合我。我已经尝试过 Horizo​​ntalscrollview,但它没有帮助。

提前致谢。

<android.support.v7.widget.CardView
            android:id="@+id/cardViewDemo1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="10dp"
            android:layout_weight="1"
            android:elevation="5dp"
            app:cardBackgroundColor="#e4a455"
            app:cardCornerRadius="10dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:padding="10dp"
                android:weightSum="1">

                <FrameLayout
                    android:id="@+id/frameDemoOne"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight=".2">

                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:paddingBottom="3dp"
                        android:paddingLeft="5dp"
                        android:paddingRight="5dp"
                        android:paddingTop="3dp"
                        android:scaleType="fitXY"
                        android:src="@drawable/demo_one" />

                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:src="@drawable/frame" />

                </FrameLayout>


                <android.support.v7.widget.CardView
                    android:id="@+id/cardViewDemo3"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginTop="5dp"
                    android:layout_weight=".8"
                    app:cardBackgroundColor="#e9e6e3"
                    app:cardCornerRadius="10dp">

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

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerInParent="true"
                            android:text="DEMOVIDEOONE"
                            android:textColor="#c9750f"
                            android:textSize="15sp"
                            android:textStyle="bold" />

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


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

        <android.support.v7.widget.CardView
        android:id="@+id/cardViewDemo2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="10dp"
        android:layout_weight="1"
        android:elevation="5dp"
        app:cardBackgroundColor="#e4a455"
        app:cardCornerRadius="10dp">

        <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:padding="10dp"
        android:weightSum="1">

        <FrameLayout
        android:layout_weight=".2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageView
        android:padding="5dp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:src="@drawable/demo_one" />

        <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/frame" />

        </FrameLayout>


        <android.support.v7.widget.CardView
        app:cardBackgroundColor="#e1b784"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="5dp"
        android:layout_weight=".8"
        app:cardCornerRadius="10dp">

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

        <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="DEMOVIDEOONE"
        android:textColor="#fff"
        android:textSize="15sp"
        android:textStyle="bold" />

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


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

【问题讨论】:

    标签: android android-layout android-cardview horizontal-scrolling


    【解决方案1】:

    使用NestedScrollView 作为两个CardView 的容器。

    这是一个例子:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
    
                <android.support.v7.widget.CardView
                    android:id="@+id/card_view_one"
                    android:layout_width="300dp"
                    android:layout_height="200dp">
    
                    <!-- Content -->
                </android.support.v7.widget.CardView>
    
                <android.support.v7.widget.CardView
                    android:id="@+id/card_view_two"
                    android:layout_width="300dp"
                    android:layout_height="200dp">
    
                    <!-- Content -->
                </android.support.v7.widget.CardView>
    
            </LinearLayout>
        </android.support.v4.widget.NestedScrollView>
    </RelativeLayout>
    

    【讨论】:

      猜你喜欢
      • 2017-01-26
      • 2019-08-24
      • 2016-01-29
      • 1970-01-01
      • 2014-10-05
      • 1970-01-01
      • 1970-01-01
      • 2017-05-15
      • 1970-01-01
      相关资源
      最近更新 更多