卧式RecyclerView顶部的滚动条 [英] Scrollbar on Top Side in Horizontal RecyclerView

查看:141
本文介绍了卧式RecyclerView顶部的滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作 Horizo​​ntal RecyclerView 的简单演示.

I am working on the Simple demo of Horizontal RecyclerView.

我想与recyclerview一起显示滚动条.因此,我在XML中添加了android:scrollbars="horizontal"android:scrollbarSize="5dp".

I want to display scrollbar along with the recyclerview. So I have added android:scrollbars="horizontal" and android:scrollbarSize="5dp" in XML.

我能够获得滚动条,但它显示在底部.我想要实现的是将其显示在顶部. .我发现了一些类似的问题,但是这些问题都不是针对 horizo​​ntal recyclerView +顶部滚动条的.

这是到目前为止我尝试过的代码:

Here is the code which I have tried so far:

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

谢谢!

推荐答案

我已经搜索了几个小时,但没有找到符合您要求的任何内容.但是有些三脚架或一些hacky代码可以根据您的要求获得输出.

I have searched couple of hours but not found anything as per your requirement. But there are some trikes or do with some hacky code we can get output as per your requirement.

在XML文件中,如下所示设置 RecyclerView

Set your RecyclerView as below in your xml file.

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

以相反的顺序将数据放入您的列表 ArrayList ,因为我们需要旋转recyclerviews,所以当我们旋转它时,数据将显示为ASEC订单.

Put your data in revers order in your List or ArrayList because we need to rotate the recyclerviews so when we rotate it then our data will be display as an ASEC order.

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

现在,最后,在您的适配器中,请按如下所示的反转方向旋转所有视图.

Now last, In your adapter please rotate your all view in revers direction like below.

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

如果您按上述方式进行编码,则您的商品及其输出如下所示:输出

If you do code as above then your item and its output look like this OutPut

请确保执行此类代码,因为android将不对此类代码负责,但是根据您的要求,您可以这样做.

Please make sure to doing this kind of code because android will not responsible for this kind of code, but as per your requirement you can do like this.

这篇关于卧式RecyclerView顶部的滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆