HorizontalScrollView 中的自定义视图无法滚动

5
我在 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()方法中,我绘制了一些文本和位图。问题在于自定义视图的宽度变得比屏幕宽度更大,而水平滚动视图没有滚动,就好像它被禁用了。这是什么原因呢?

你可以尝试将自定义视图的宽度更改为fill_parent,看看是否会有所变化。 - C.d.
1个回答

0
如果您的MyCustomView始终大于屏幕宽度,则将HorizontalScrollView的宽度设置为其内容大小是安全的。请尝试以下操作:
<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>

我认为现在的问题是HorizontalScrollView的宽度被固定为fill_parent。滚动默认已启用,您尚未手动更改,因此这不是问题所在。


当我尝试了你的解决方案后,我的自定义滚动内容变得不可见了,真的不知道为什么。 - Mina Wissa
дҪ иғҪеҸ‘еёғж•ҙдёӘеёғеұҖж–Ү件еҗ—пјҹд»…д»…ж”№еҸҳandroid:layout_widthдёҚеә”иҜҘеҜјиҮҙиҝҷз§Қжғ…еҶө... - tipycalFlow
此布局被填充以成为ListView的项视图。 - Mina Wissa
好的...那么尝试将滚动视图的“layout_width”设置为320(或者您正在使用的AVD屏幕大小)。 - tipycalFlow

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接