如何禁用 HorizontalScrollView
我正在编写一个自定义 ChipGroup 类,在布局中我有一个 HorizontalScrollView 和一个 Material ChipGroup 。在我的构造函数中,我传递了一个名为 "isScrollable"
的布尔值,因为我希望它可以配置滚动。
如果滚动配置为 false,是否有办法禁用 HorizontalScrollView 的滚动?
I'm programming a custom ChipGroup class and in the layout I have a HorizontalScrollView and a Material ChipGroup inside. In my constructor I pass a boolean called "isScrollable"
because I want it to be configurable the scrolling.
Is there a way to inactivate the scroll of the HorizontalScrollView if scrolling is configured as false?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
扩展ScrollView并重写onTouchEvent方法返回
当某些条件匹配时为 false。
水平方向,无论它是否在 ScrollView 中 - a
ScrollView 仅提供垂直滚动(您需要一个
HorizontalScrollView 用于水平滚动)。
图像本身拉伸有问题——这没有任何问题
对于 ScrollView,您可以更改 ImageView 的缩放方式
使用 android:scaleType 属性 (XML) 或 setScaleType 方法
例如 ScaleType.CENTER 不会拉伸您的图像,并将其以其原始大小居中。
您可以按如下方式修改 ScrollView 以禁用滚动:
然后,
在您的 XML 文件中(只需将 ScrollView 更改为特殊的 LockableScrollView)。
然后调用
以禁用视图的滚动。
extend to ScrollView and override the onTouchEvent method to return
false when some condition is matched.
horizontally regardless of whether it is in a ScrollView or not - a
ScrollView provides only vertical scrolling (you need a
HorizontalScrollView for horizontal scrolling).
have a problem with the image stretching itself -- this has nothing
to do with the ScrollView, you can change how an ImageView scales
with the android:scaleType property (XML) or the setScaleType method
for instance ScaleType.CENTER will not stretch your image and will center it at it's original size.
You could modify ScrollView as follows to disable scrolling:
then,
in your XML file (just changed the ScrollView to your special LockableScrollView).
Then call
to disable scrolling of the view.