lundi 13 avril 2015

Custom view not drawing beyond bounds of screen


Vote count:

0




I have a custom view which is nested inside of a ScrollView. The idea is that the custom view can be longer than the height of the screen, so when you swipe through the ScrollView you can see all of its contents.


In order to do this I adjust the clip of the custom view's canvas like this:



@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);

canvas.clipRect(mCanvasArea, Region.Op.REPLACE);
}


Where mCanvasArea is a pre-generated RectF which represents the entire area the canvas can draw. I logged it's value @ 10308.


However when the app runs, the custom view is unscrollable, it acts as if the visible content represents all of the content in the canvas, but I can see more peeking up from the bottom of the screen.


Here is my XML declaration for the view:



<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/activity_toolbar"
android:fillViewport="true">

<com.myapp.CustomView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

</ScrollView>


(I had to add fillViewport in order to get the content to show up in the first place)


Is there anything else that needs to be done in order yo make the view scroll?



asked 20 secs ago







Custom view not drawing beyond bounds of screen

Aucun commentaire:

Enregistrer un commentaire