【问题标题】:Scrollbar on Top Side in Horizontal RecyclerView水平 RecyclerView 顶部的滚动条
【发布时间】:2018-05-19 11:54:22
【问题描述】:

我正在开发Horizo​​ntal RecyclerView的简单演示。

我想与回收视图一起显示滚动条。所以我在 XML 中添加了android:scrollbars="horizontal"android:scrollbarSize="5dp"

我能够获得滚动条,但它显示在底部。我想要实现的是在 Top 上显示它。我发现了一些这样的问题,但没有一个是针对 horizo​​ntal recyclerView + top side scrollbar 的。

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

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

谢谢!

【问题讨论】:

  • 看看imgur.com/a/3WI9v 顶部的滚动条。如果你想要这样,请 ping 我。

标签: android android-recyclerview android-scrollbar


【解决方案1】:

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

在您的 xml 文件中如下设置您的 RecyclerView

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

将您的数据在您的ListArrayList 中以相反的顺序排列,因为我们需要轮换recyclerviews,所以当我们轮换它时,我们的数据将显示为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();
        }

最后,在你的适配器中,请像下面这样反向旋转你的所有视图。

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

请确保做这种代码,因为android不会对这种代码负责,但根据您的要求,您可以这样做。

【讨论】:

  • 我也认为这是一种快速修复方法,但这不是推荐的方法。但是,非常感谢您试图弄清楚。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多