如何在android中滚动和缩放画布内容?
我有自定义视图,当加载此视图时,我正在将位图绘制到画布中。此位图基于pdf页面的长度和大小绘制。我为用户提供了两个按钮,用于在画布上绘制路径和文本 通过两种方式将此视图添加到我的父视图中: 一,。在父布局内创建子布局(LinearLayout或RelativeLayout),并以编程方式在CustomView中添加滚动条,并在childLayout中添加自定义视图 xml布局:如何在android中滚动和缩放画布内容?,android,canvas,scroll,zooming,Android,Canvas,Scroll,Zooming,我有自定义视图,当加载此视图时,我正在将位图绘制到画布中。此位图基于pdf页面的长度和大小绘制。我为用户提供了两个按钮,用于在画布上绘制路径和文本 通过两种方式将此视图添加到我的父视图中: 一,。在父布局内创建子布局(LinearLayout或RelativeLayout),并以编程方式在CustomView中添加滚动条,并在childLayout中添加自定义视图 xml布局: <RelativeLayout xmlns:android="http://schemas.android.co
<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>
这里我的问题是,当我在onDraw()的画布上绘制路径时,它是绘制路径,但当我润色时,路径是静止的。如果我在mCanvas上绘制路径,它是绘制路径,并且没有重置。但是如何使用onDraw()画布滚动此mCanvas。只需使用canvas.concat(矩阵)方法,在canvas.save()之后调用它,确保在onDraw方法的末尾调用canvas.restore()。是的,我在onDraw()方法中编写了这3个方法,但这不起作用。在我的例子中,onDraw(canvas canvas)方法canvas正在绘制pdf页面的位图。因此,对于在画布上绘制路径,我在onTouch(MotionEvent event)方法中使用了不同的画布。不同的画布?什么不同的画布?意味着,使用onDraw()画布,我正在绘制pdf位图,并为画布和位图创建新的构造函数,即mBitmap=bitmap.createBitmap(w,h,bitmap.Config.ARGB_8888);mCanvas=新画布(mBitmap);我使用这个mCanvas来绘制路径和drawingText
<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>
@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.
}