2017-12-05 42 views
5

私はのHorizo​​ntal RecyclerViewのシンプルなデモを行っています。横のRecyclerViewの上部のスクロールバー

私はrecyclerviewと共にスクロールバーを表示したいと思います。だから私はandroid:scrollbars="horizontal"android:scrollbarSize="5dp"をXMLに追加しました。

スクロールバーを取得できますが、下部に表示されています。私が達成したいのは、それをトップに示すことです。私はこのようないくつかの質問を見つけましたが、どれもhorizo​​ntal 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でスクロールバーが上に表示されます。あなたがこのようにしたいなら、私にpingしてください。 – Shailesh

答えて

1

私は何時間も検索しましたが、あなたの要件には何も見つかりませんでした。しかし、いくつかのトライクがあるか、あなたの要件に応じて出力を得ることができるいくつかのハッキーなコードがあります。

RecyclerViewをxmlファイルに設定します。

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

、我々はそれを回転させるときに、次に我々のデータはASEC順序として表示されますrecyclerviewsを回転させる必要があるので、あなたのListArrayListで折返し順にデータを入れてください。

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

私はこれを迅速な修正と考えていますが、これを行うのは推奨された方法ではありません。しかし、あなたが把握しようとしたように、おかげです。 –

関連する問題