ScrollView和CustomView滚动

时间:2011-07-26 09:16:47

标签: java android scrollview

我有一个像这样定义的ScrollView:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
       android:id="@+id/scrollv"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content">

       <com.test.myview android android:id="@+id/myview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</ScrollView>

MyView从View扩展。

在MyView中的

我有一个刻度为1.5的Bitmap。似乎scollview工作正常,因为当我向上或向下滚动时出现淡化边缘,但是在onDraw()中绘制的图像(作为drawBitmap(bm ..))不会滚动显示“隐藏” part ..它滚动2px然后停止..当它到达onScrollChanged(int,int,int,int) - 我得到所有的值都是0那里..我甚至尝试用scollTo显式设置滚动或scrollBy方法,没有帮助。所以我想这是我错误的内容......

我做错了吗?我使用的CustomView是基本视图,其中包含或多或少的常用方法覆盖(onMeasure,onDraw,onTouchEvent ...)。

1 个答案:

答案 0 :(得分:4)

您需要为自定义视图使用固定的宽度和高度。