如何在Android的编程设置滚动条拇指? [英] How to set scrollbar thumb programmatically in Android?

查看:166
本文介绍了如何在Android的编程设置滚动条拇指?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道列表视图可以在这样的XML设置滚动条拇指安卓scrollbarThumbVertical

I know listview can set scrollbar thumb in XML like this Android:scrollbarThumbVertical etc.

不过,我创建了Java code一个ListView实例,我可能需要设置不同的卷动条。有没有一种方法可以通过编程设置滚动条拇指?

But I'm creating a listview instance in the java code and I maybe need to set different scrollbar thumb. Is there a method can set scrollbar thumb programmatically?

推荐答案

我不知道这个问题的答案,但有点周围挖之后,我不认为这是可能毫不费力的负担。

I didn't know the answer to this, but after a bit of digging around I don't think it's possible without a load of hassle.

此XML属性实际上是与一个查看,不是的ListView 相关 - 在Android查看源代码code,似乎它是设置在垂直拇指可拉伸的唯一地方是<一个href="https://github.com/android/platform_frameworks_base/blob/master/core/java/android/view/View.java#L3259"相对=nofollow>initializeScrollbars的方法。现在,这个方法是不是私人的,所以我们可以扩展视图的子女和重写此方法,但问题是,需要设置拇指绘制的ScrollabilityCache,一个重要组成部分是私人没有任何getter方法​​。

This xml attribute is actually associated with a View, not a ListView - In the Android View source code, it seems that the only place that it is setting the vertical thumb drawable is the 'initializeScrollbars' method. Now this method isn't private, so we can extend any child of View and override this method, but the issue is that a crucial component needed to set the thumb drawable, the ScrollabilityCache, is private without any getter methods.

所以无需重写大量的code,我不认为有任何简单的方法来做到这一点 - !对不起

So without rewriting a lot of the code I don't think there's any easy way to do this - sorry!

这篇关于如何在Android的编程设置滚动条拇指?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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