2017-05-06 52 views
0

我試圖horziental滾動添加到各行的垂直RecycleView裏面,垂直滾動按預期工作,但horizentalScrolling不每一行的如何水平滾動條添加到每個行中的垂直recycleView

這裏我對recycleView

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

<android.support.v7.widget.RecyclerView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/myrecycleView" 
    android:scrollbars="vertical" /> 

</LinearLayout> 

的佈局和每行的佈局代碼

<?xml version="1.0" encoding="utf-8"?> 
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:fillViewport="true"> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/linearLayout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:focusable="true" 
     android:clickable="true" 
     android:orientation="horizontal"> 

     <TextView 
      android:id="@+id/textView" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 

      android:gravity="center" 
      android:text="1" 
      android:textColor="#ffffff" 
      android:textSize="@dimen/textSizeLarge" 
      android:textStyle="bold" /> 

     <me.test.com.myCustomView 
      android:id="@+id/myCustomView" 
      android:layout_width="1000dp" 
      android:layout_height="50dp" /> 
    </LinearLayout> 
</HorizontalScrollView> 

我嘗試添加horizantalScrollView但沒有奏效,

回答

0

嘗試獲取LinearLayoutManager並將其設置爲Horizo​​ntal並將其包裝爲像這樣的recyclerView。

<android.support.v7.widget.RecyclerView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/my_recycler_view" //->add this 
    android:scrollbars="vertical" /> 

LinearLayoutManager layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false); 

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.my_recycler_view); 
reclyclerView.setLayoutManager(layoutManager); 
recyclerView.setMinimumWidth(200); 
+0

我試過,但都行,現在是彼此相鄰horizo​​ntalally – user126789