I have custom view,When loading this view I am drawing bitmap into canvas this bitmap drawn based on pdf pages length and size.And I am providing 2 buttons to user for drawing paths and drawing text on canvas.
For adding this View into my parent in two ways :
1 . Creating child layout(LinearLayout or RelativeLayout) inside parent layout and programatically adding Scroller in CustomView and adding custom view into childLayout.
xml Layout :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/custom_pdf_viewer_parent_relative_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/custom_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
/RelativeLayout>
2. Creating child layout (ScrollView inside Horizontal Scrollview) inside Parent layout and adding custom view into childLayout(ScrollView).
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.pakagename.CustomHorizontalScrillView
android:id="@+id/pages_horizontal_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/top_buttons_layout"
android:fillViewport="true" >
<com.pakagename.CustomVerticalScrollView
android:id="@+id/pages_vertical_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" />
</com.cudrivepdfeditor.CustomHorizontalScrillView>
</RelativeLayout>
And for adding scroll into canvas I am using onMeasure(int widthMeasureSpec, int heightMeasureSpec).
In first case :
But this onMeasure is not working in first case. Because custom view is added into LinearLayout.But by programatically I am adding scroller into custom view.I don't know why onMeasure is not working.But in debugging mode widthMeasureSpec,heightMeasureSpec are not null and not 0 those have different values what exactly file have.
In second case :
In this case I am adding custom view into my verticalscrollview this verticalscrollview placed in horizantalscrollview.In this case onMeasure() method calls multiple times and it's adding scroll into customview and canvas.Canvas content also scrolls when I am scrolling.
But In my case I have zooming functionality also.When I click on zoom++ button canvas is not zooming and onMeasure() also not giving proper width and height.
in my zoom++() I called measure(requiredWidth, requiredHeight) method.
How I can scroll and zoom canvas content?Any one have any idea please help me.I stuck in this functionality from very long time.
Edit#1 :
@Override
public void onDraw(Canvas canvas) {
drawPages(canvas); // This drawPages(canvas) method draw a pages on canvas
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
this.width = w;
this.height = h;
mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
mCanvas = new Canvas(mBitmap); // Here I am creating new bitmap on canvas and I am drawing paths and text on this canvas.
}
Here my problem was when I am drawing paths on canvas of onDraw() it's draw a paths but when I touch up that paths are rest.And if I draw a path on mCanvas it's drawing paths and it's not resetting.But how I can scroll this mCanvas with onDraw() canvas.