1

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.

user123456
  • 123
  • 1
  • 15
  • just use Canvas.concat(Matrix) method,, call it after canvas.save(), make sure you call canvas.restore() at the end of onDraw method – pskink Jun 16 '14 at 08:27
  • yes,I written this 3 methods in my onDraw() method but this are not working. – user123456 Jun 16 '14 at 09:30
  • in my case OnDraw(Canvas canvas) method canvas is drawing bitmaps of pdf pages.so for drawing paths on canvas I am using different canvas in onTouch(MotionEvent event) method. – user123456 Jun 16 '14 at 09:37
  • different Canvas? what different Canvas? – pskink Jun 16 '14 at 09:44
  • Means,with onDraw() canvas I am drawing bitmaps of pdf and creating new constructors for canvas and bitmap that is mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); and I am using this mCanvas for drawing paths and drawingText – user123456 Jun 16 '14 at 09:52
  • ok, i have no idea what you're talking about – pskink Jun 16 '14 at 09:55
  • see my answer here http://stackoverflow.com/questions/21633545/android-imageview-scaling-and-translating-issue on how to use a Matrix for panning, scaling and rotating – pskink Jun 16 '14 at 09:59
  • it doesn't clarify anything, what's done in drawPages(canvas);, what paths, what resetting? i dont have a crystal ball and cannot read your minds – pskink Jun 16 '14 at 10:18

0 Answers0