简体   繁体   English

ScrollView和CustomView滚动

[英]ScrollView and CustomView scrolling

I have a ScrollView defined like this: 我有一个这样定义的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>

And MyView is extended from View. MyView是从View扩展的。

in MyView I have a Bitmap drawn with scale of 1.5. 在MyView中,我以1.5的比例绘制了位图。 It seems as the scollview is working fine since the fading edges appear when I scroll up or down, but then the Image that is drawn in onDraw() (as drawBitmap(bm..)), is not scrolled to show the 'hidden' parts .. it scrolls for 2px's and then stops.. when it gets to onScrollChanged(int, int, int, int) - I get that all of the values are 0 there.. I even try to explicitly set the scroll with scollTo or scrollBy methods, no help. scollview似乎工作正常,因为当我向上或向下滚动时会出现褪色边缘,但是随后在onDraw()中绘制的图像(如drawBitmap(bm ..))不会滚动以显示“隐藏”零件..它滚动2px,然后停止..当它到达onScrollChanged(int,int,int,int)-我得到那里的所有值都是0。我什至尝试用scollTo或显式设置滚动scrollBy方法,没有帮助。 So I suppose it's the content that I am mistakening somehow... 所以我想这是我误会的内容...

Am I doing something wrong? 难道我做错了什么? The CustomView I use is basic View with more or less of the common methods overriden (onMeasure, onDraw, onTouchEvent...). 我使用的CustomView是基本视图,具有或多或少的常用方法(onMeasure,onDraw,onTouchEvent ...)被覆盖。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM