2017-12-05 29 views
5

Tôi đang làm việc trên bản demo đơn giản của Ngang RecyclerView.Thanh cuộn ở phía trên cùng trong Horizontal RecyclerView

Tôi muốn hiển thị thanh cuộn cùng với recyclerview. Vì vậy, tôi đã thêm android:scrollbars="horizontal"android:scrollbarSize="5dp" trong XML.

Tôi có thể lấy Thanh cuộn nhưng thanh này hiển thị ở dưới cùng. Những gì tôi muốn đạt được là hiển thị nó trên đầu trang. Tôi đã tìm thấy một số câu hỏi như thế này nhưng không có câu hỏi nào trong số đó là dành cho horizontal recyclerView + thanh cuộn phía trên cùng.

Đây là mã mà tôi đã cố gắng cho đến nay:

<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

Cảm ơn!

+0

có giao diện https://imgur.com/a/3WI9v mà thanh cuộn của bạn ở trên cùng. nếu bạn muốn như thế thì hãy ping tôi. – Shailesh

Trả lời

1

Tôi đã tìm kiếm vài giờ nhưng không tìm thấy bất kỳ điều gì theo yêu cầu của bạn. Nhưng có một số trikes hoặc làm với một số mã hacky chúng tôi có thể nhận được đầu ra theo yêu cầu của bạn.

Đặt RecyclerView như dưới đây trong tệp xml của bạn.

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

Đặt dữ liệu của bạn trong revers đặt trong List hoặc ArrayList của bạn bởi vì chúng ta cần phải xoay recyclerviews như vậy khi chúng tôi xoay nó sau đó dữ liệu của chúng tôi sẽ được hiển thị như một trật tự ASEC.

//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(); 
     } 

Cuối cùng, trong bộ điều hợp của bạn, vui lòng xoay tất cả chế độ xem theo hướng ngược lại như dưới đây.

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); 
     } 
    } 

Nếu bạn làm mã như trên thì mục của bạn và sản lượng của nó trông như thế này OutPut

Hãy chắc chắn để thực hiện loại mã này vì Android sẽ không chịu trách nhiệm cho các loại mã này, nhưng theo yêu cầu của bạn, bạn có thể làm như thế này.

+0

Tôi cũng đã nghĩ rằng đây là một sửa chữa nhanh chóng, nhưng đây không phải là cách được khuyến khích để làm điều đó. Tuy nhiên, cảm ơn rất nhiều như bạn đã cố gắng tìm ra. –

Các vấn đề liên quan