首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在android中创建固定大小和居中对齐的水平滚动条

如何在android中创建固定大小和居中对齐的水平滚动条
EN

Stack Overflow用户
提问于 2021-03-23 11:04:41
回答 1查看 85关注 0票数 1

UI Design for Reference

我想设计一个水平滚动条只在视图的中心,它应该附加到recyclerView。基本上,我想限制水平滚动条的长度。

EN

回答 1

Stack Overflow用户

发布于 2021-03-23 14:41:16

更新

添加一个水平滚动条到recyclerview,并设置trumb和bg

代码语言:javascript
运行
复制
 <androidx.recyclerview.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:scrollbars="horizontal"
    android:scrollbarStyle="outsideInset"
    android:fadeScrollbars="false"
    android:overScrollMode="never"
    android:scrollbarSize="5dp"
    android:scrollbarThumbHorizontal="@drawable/aa_scrollbar"
    android:scrollbarTrackHorizontal="@drawable/aa_scrollbar_bg"
    />

aa_scrollbar.xml:

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 
    <item
        android:width="@dimen/dpi_80px"
        android:left="@dimen/dpi_20px"
        android:right="@dimen/dpi_20px">
        <shape>
            <corners android:radius="@dimen/dpi_10px" />
            <solid android:color="?attr/Theme_color" />
        </shape>
    </item>
 
</layer-list>

aa_scrollbar_bg.xml

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 
    <item
        android:left="@dimen/dpi_20px"
        android:right="@dimen/dpi_20px">
        <shape>
            <corners android:radius="@dimen/dpi_10px" />
            <solid android:color="@color/scrollbar_bg" />
        </shape>
    </item>
</layer-list>

可以根据需要重新调整像dpi_20px这样的段落。

添加一个水平滚动条,以回收视图.May,这有助于您。

代码语言:javascript
运行
复制
   <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="horizontal"
        android:scrollbarStyle="outsideInset"
        android:fadeScrollbars="false"
        android:overScrollMode="never"
        android:scrollbarSize="5dp"
        android:scrollbarThumbHorizontal="#DF9797"
        android:scrollbarTrackVertical="#fff"
        />
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66756703

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档