android - 如何设置ListView的滚动条向右偏移

标签 android android-layout listview scrollbar

请在回答之前阅读,因为这可能不是您认为的问题

这是我的 ListView

<ListView
        android:id="@+id/ist"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:divider="@color/ca”
        android:dividerHeight="@dimen/h1”
        android:gravity="center" />

一切正常,除了滚动条显然有一个我没有设置的 paddingRightlayout_marginRight。滚动条本身——不是我从适配器填充的行项目。所以我看到的是滚动条从右边缘显示大约 10dp,而我的行的内容填满了屏幕的宽度。我想要的是滚动条完全显示在内容的右侧,这样它就不是沿 z 轴的视觉叠加。

最佳答案

尝试使用 scrollbarStyle。我发现 android:scrollbarStyle="outsideOverlay" 效果最好/看起来最好。

控制滚动条的样式和位置。

http://developer.android.com/reference/android/view/View.html#setScrollBarStyle(int)

public void setScrollBarStyle (int style)

Added in API level 1 Specify the style of the scrollbars. The scrollbars can be overlaid or inset. When inset, they add to the padding of the view. And the scrollbars can be drawn inside the padding area or on the edge of the view. For example, if a view has a background drawable and you want to draw the scrollbars inside the padding specified by the drawable, you can use SCROLLBARS_INSIDE_OVERLAY or SCROLLBARS_INSIDE_INSET. If you want them to appear at the edge of the view, ignoring the padding, then you can use SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET.

Related XML Attributes android:scrollbarStyle Parameters style the style of the scrollbars. Should be one of SCROLLBARS_INSIDE_OVERLAY, SCROLLBARS_INSIDE_INSET, SCROLLBARS_OUTSIDE_OVERLAY or SCROLLBARS_OUTSIDE_INSET. See Also SCROLLBARS_INSIDE_OVERLAY SCROLLBARS_INSIDE_INSET SCROLLBARS_OUTSIDE_OVERLAY SCROLLBARS_OUTSIDE_INSET

关于android - 如何设置ListView的滚动条向右偏移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23714589/

相关文章:

android - 如何从 Google Fit 历史记录中获取心率值?

android - 将 ImageView 放在 Camera Preview 之上

android - 如何在android中为线性布局设置页眉和页脚

c# - 在 DataPager 中获取事件号码页

php - Android登录并注册MySQL HTTPS网站

android - QSettings 在 Android 下的 Qt 上无法正常工作

android - 为什么 Android Studio 在编辑 xml 文件或更改设计时会变慢?

android - ScrollingToolbarLayout 没有 "up"按钮

java - 重新启动 Android 应用程序时出现 SQlite 错误

android - 如何从服务器查看 mp3 文件的 ListView