Horizo​​ntalScrollView 内的自定义视图不滚动

发布于 2025-01-07 09:53:27 字数 564 浏览 1 评论 0原文

我在 Horizo​​ntalScrollView 中有一个自定义视图,如下所示:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

决绝 2025-01-14 09:53:27

如果您的 MyCustomView 始终大于屏幕宽度,则可以安全地将 Horizo​​ntalScrollView 的宽度设置为等于其内容。尝试以下操作:

<HorizontalScrollView
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:fillViewport="true"
     >

    <com.mina.demo.customwidgets.MyCustomView
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        />

</HorizontalScrollView>

我认为现在的问题是 Horizo​​ntalScrollView 的宽度固定为 fill_parent。默认情况下启用滚动,并且您没有手动更改它,所以这不是问题。

If your MyCustomView is always larger than the screen width, then it's safe to set the width of HorizontalScrollView equal to its contents. Try the following:

<HorizontalScrollView
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:fillViewport="true"
     >

    <com.mina.demo.customwidgets.MyCustomView
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        />

</HorizontalScrollView>

I think the problem right now is that the width of the HorizontalScrollView is fixed at fill_parent. The scrolling is enabled by default and you haven't manually changed it so that's not the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文