0

我有两个cardview有不同的childview,我希望他们显示在我的屏幕的底部,并希望他们水平滚动,我已阅读其他文档。但没有一个适合我。我曾尝试Horizo​​ntalscrollview,但它没有帮助。如何使两个cardview水平滚动?

在此先感谢。

<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> 

回答

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>