0

동시에 Recycler보기에 가로 및 세로 스크롤을 구현하려고합니다. 8 열의 표를 표시해야하므로 가로 및 세로 스크롤을 같은 시간.안드로이드 : recyclerview에 대한 가로 및 세로 스크롤

리스트 행에 HorizontalScrollView을 시도했지만 가로로 스크롤하고 있습니다. 나는 또한 recyclerview의 부모 만

list_row.xml

<?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:focusable="true" 
android:paddingLeft="16dp" 
android:paddingRight="16dp" 
android:paddingTop="10dp" 
android:paddingBottom="10dp" 
android:clickable="true" 
android:background="?android:attr/selectableItemBackground" 
android:orientation="vertical"> 


<TextView 
    android:id="@+id/title" 
    android:textColor="@color/title" 
    android:textStyle="bold" 
    android:layout_alignParentTop="true" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 

    android:text="aaa"/> 

<TextView 
    android:layout_toRightOf="@+id/title" 
    android:id="@+id/genre" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="20dp" 
    android:text="bbb"/> 

<TextView 
    android:layout_toRightOf="@+id/genre" 
    android:id="@+id/year" 
    android:textColor="@color/year" 
    android:layout_width="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_marginLeft="20dp" 
    android:layout_height="wrap_content" 
    android:text="ccc"/> 

</RelativeLayout> 

Activity_main.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="horizontal" > 
<HorizontalScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:fillViewport="true" > 
<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" > 
<android.support.v7.widget.RecyclerView 
    android:id="@+id/recycler_view" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"/> 
</LinearLayout> 
</HorizontalScrollView> 
</LinearLayout> 

작동하지의 수 중 하나로서 HorizontalScrollView 시도 나에게 아이디어를 말해줘.

답변

0

내가보기에 가장 좋은 해결책은 하나의보기에서 가로 및 세로 스크롤이 하나의 FrameLayout 안에 배치하는 것입니다. 그런 다음보기에서 OnTouch를 구현해야합니다 (활동에서이 작업을 수행 할 수 있음). 터치 포인터가 움직일 때 스크롤해야합니다. XML :

<FrameLayout 
android:id="@+id/TwoWaysScrollableContainer" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:clipToPadding="false"> 
    <YourView 
     android:id="@+id/GridContainer" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:clipToPadding="false" /> 
</FrameLayout> 

의 C# (내가 자 마린 사용하지만 자바는 너무 많은 differencies이없는 것 내가 생각하는) :

public class MyActivity : Activity 
    { 
     private MyView _myView; //Can be GridView, relative layout or wathever 
     private float _startX, _startY,_prevDx, _prevDy, _dx,_dy; 
     protected override void OnCreate(Bundle bundle) 
     { 
      base.OnCreate(bundle); 
     _myView = FindViewById<MyView>(Resource.Id.GridContainer); 
     } 

     public bool OnTouch(View v, MotionEvent e) 
     { 
      switch (e.Action) 
      { 
       case MotionEventActions.Down: 
        { 

         mode = Mode.DRAG; 
         startX = e.GetX() - prevDx; 
         startY = e.GetY() - prevDy; 

         break; 
        } 
       case MotionEventActions.Move: 
        { 
         /* you also could add logic to prevent your view from scrolling out of you grid bounds*/ 
         if (mode == Mode.DRAG) 
         { 
          dx = startX - e.GetX(); 
          dy = startY - e.GetY(); 
          _myView.ScrollBy((int)(dx), (int)(dy)); 

          startX = e.GetX(); 
          startY = e.GetY(); 
         } 
         break; 
        } 
       case MotionEventActions.Up: 
        { 
         mode = Mode.NONE; 
         prevDx = dx; 
         prevDy = dy; 
         break; 
        } 
       } 
       return true; 
     } 
    } 

내가이 아무튼 알고 여기

은 예입니다 귀하의 질문에 직접 대답하지 않습니다 (저는 재활용업자 관점에 관해 많이 알지 못합니다).하지만 여전히 귀하를 도울 수 있기를 바랍니다. 저는 이것을 타일 엔진에 사용했고 트릭을 아주 잘했습니다.

관련 문제