I have a custom view that extends View. It displays drawn shapes, and allows the user to add to those drawings via drawing touch events to the View via onDraw.
I've enabled the ScaleGestureDetector so that the user can zoom in on a particular section and draw, but as I am using single-touch to draw, they cannot use their finger to pan around the zoomed in View.
I've tried to enable scrollbars for the View such that when they are zoomed in, the scrollbars are displayed and can be used by the user to pan... but I simply can't get the scrollbars to be displayed.
Essentially, what I am doing is to call the View's awakenScrollBars()
method in my ScaleListener's onScale()
method when the user is zoomed in, which triggers invalidate()
. I enabled the scrollbars via both the XML, and programatically in onCreate()
, but I can't trigger the scrollbars to be visible. Here is my XML:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.package.name.Canvas
android:id="@+id/canvas"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:scrollbars="horizontal|vertical" />
</FrameLayout>
And here is my onCreate():
// set scrollbars
setHorizontalScrollBarEnabled(true);
setVerticalScrollBarEnabled(true);
In onDraw, I can verify that the scrollbars are enabled via isHorizontalScrollBarEnabled()
and isVerticalScrollBarEnabled()
, and awakenScrollBars()
in onScale()
returns true, but the scroll bars are just not visible.
Any suggestions on how to proceed? Containing the custom View in a ScrollView layout doesn't seem to be an option, as that only supports vertical scrolling.
Thanks,
Paul
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…