HorizontalScrollView 内的自定义视图不滚动
我在 HorizontalScrollView 中有一个自定义视图,如下所示:
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
>
<com.mina.demo.customwidgets.MyCustomView
android:layout_width="wrap_content"
android:layout_height="50dp"
/>
</HorizontalScrollView>
在 MyCustomView onDraw() 方法中,我绘制一些文本和位图。
问题是自定义视图的宽度变得大于屏幕宽度,并且环绕水平滚动视图不会像禁用一样滚动。
这可能是什么原因?
I have a custom view inside a HorizontalScrollView like this:
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
>
<com.mina.demo.customwidgets.MyCustomView
android:layout_width="wrap_content"
android:layout_height="50dp"
/>
</HorizontalScrollView>
In MyCustomView onDraw() method, I draw some text and bitmaps.
the problem is that the width of the custom view becomes larger than the screen width, and wrapping horizontal scroll view does not scroll as if it is disabled.
what can be the reason for this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的
MyCustomView
始终大于屏幕宽度,则可以安全地将HorizontalScrollView
的宽度设置为等于其内容。尝试以下操作:我认为现在的问题是
HorizontalScrollView
的宽度固定为fill_parent
。默认情况下启用滚动,并且您没有手动更改它,所以这不是问题。If your
MyCustomView
is always larger than the screen width, then it's safe to set the width ofHorizontalScrollView
equal to its contents. Try the following:I think the problem right now is that the width of the
HorizontalScrollView
is fixed atfill_parent
. The scrolling is enabled by default and you haven't manually changed it so that's not the problem.