2017-12-05 8 views
5

Horizontal RecyclerView의 간단한 데모를 작업 중입니다.수평 RecyclerView의 윗면에 스크롤 막대

recyclerview와 함께 스크롤바를 표시하고 싶습니다. 그래서 android:scrollbars="horizontal"android:scrollbarSize="5dp"을 XML에 추가했습니다.

스크롤바를 가져올 수 있지만 하단에 표시됩니다. 내가 원하는 것은 Top에 표시하는 것입니다. 나는 이와 같은 질문을 발견했지만 그 중 어느 것도 horizontal recyclerView + 상단 스크롤바에 해당되지 않습니다.

<android.support.v7.widget.RecyclerView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:isScrollContainer="false" 
    android:orientation="horizontal" 
    android:scrollbars="horizontal" 
    android:scrollbarSize="5dp" 
    android:visibility="visible" /> 

Image, that describes my query

감사 :

여기

지금까지 시도하는 코드입니다!

+0

https://imgur.com/a/3WI9v 화면에 스크롤바가 표시됩니다. 네가 이렇게하면 핑 소리 내고 싶어. – Shailesh

답변

1

몇 시간 동안 검색했지만 귀하의 요구 사항에 따라 아무것도 찾을 수 없습니다. 그러나 일부 트라이크가 있거나 귀하의 요구 사항에 따라 출력을 얻을 수있는 해킹 코드가 있습니다.

아래와 같이 xml 파일에 RecyclerView을 설정하십시오. REVERS이 List 또는 ArrayList에 위해 우리가 ASEC 순서로 다음 우리의 데이터가 될 것입니다 우리가 회전 할 때 그래서 recyclerviews를 회전 디스플레이를 필요로하기 때문에

<android.support.v7.widget.RecyclerView 
     android:id="@+id/recyclerView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:scrollbarAlwaysDrawHorizontalTrack="true" 
     android:scrollbarSize="10dp" 
     android:scrollbarStyle="outsideInset" 
     android:scrollbarThumbVertical="@color/black" 
     android:scrollbars="horizontal" 
     android:verticalScrollbarPosition="right"/> 

은 데이터를 넣습니다.

//call this method for set recyclerview 
    private void setRecyclerView() 
    { 
     //Please make sure with your item that it will be inserted in revers order then an then it will be working 
     ArrayList<String> itemList = new ArrayList<>(); 
     for (int i = 50; i > 0; i--){ 
      itemList.add("item " + i); 
     } 

     ContainerAdapter adapterMessage = new ContainerAdapter(MainActivity.this, itemList); 
     if (adapterMessage != null) 
     { 
      rvItemList.setHasFixedSize(true); 
      rvItemList.setLayoutManager(new LinearLayoutManager(MainActivity.this, 
        LinearLayoutManager.HORIZONTAL, false); 
      rvItemList.setItemAnimator(new DefaultItemAnimator()); 
      rvItemList.setAdapter(adapterMessage); 
      //here is the main line for your requirement 
      rvItemList.setRotation(180); 
      adapterMessage.notifyDataSetChanged(); 
     } 

이제 어댑터에서 모든보기를 아래와 같이 반대 방향으로 회전하십시오.

public class ViewHolder extends RecyclerView.ViewHolder 
    { 
     TextView txt_name; 
     public ViewHolder(View itemView) { 
      super(itemView); 
      txt_name = (TextView) itemView.findViewById(R.id.txt_name); 
      // here you need to revers rotate your view because your recyclerview is already rotate it so your view is also rotated and you need to revers rotate that view 
      txt_name.setRotation(-180); 
     } 
    } 

그런 다음 위와 같이 코드를 할 경우 항목과 출력이 OutPut

과 같이 코드의이 종류의 일에 확인하시기 바랍니다 때문에 안드로이드 것이다 이러한 종류의 코드에 대한 책임,하지만 당 귀하의 요구 사항은 이와 같이 할 수 있습니다.

+0

나는 이것을 빠른 수정으로 생각해 왔지만,이 방법을 권장하지는 않습니다. 그러나, 당신이 알아 내려고 노력하면서 많은 감사합니다. –