android-canvas

How to draw by finger on canvas after pinch to zoom coordinates changed in android?

时间秒杀一切 提交于 2019-12-07 23:14:08
问题 Can any body have solution regarding how to draw on canvas using finger after zoom in and zoom out? I done pinch to zoom for canvas but stucking point is not draw right coordinate. I done more R&D from google. I have CustomView Class which i share on below. public class DrawingView extends View { ArrayList<Path> pathList = new ArrayList<Path>(); Rect mRect = new Rect(); private static final int INVALID_POINTER_ID = -1; public Bitmap mMyChracter; private float mPosX; private float mPosY;

Fill intersection area of objects

99封情书 提交于 2019-12-07 22:41:10
问题 I want to fill the intersection area of a rectangle and a circle using Android Canvas like in the image below: How can I achieve this? Update : here my code public static class MyView extends View { private Paint paint; public MyView(Context context) { super(context); init(); } public MyView(Context context, AttributeSet attrs) { super(context, attrs); init(); } public MyView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } @RequiresApi

Set rotation and position of bitmap

最后都变了- 提交于 2019-12-07 20:43:24
问题 I would like to know how i both can change the position of a bitmap and at the same time rotate it. Im drawing at a canvas. Im currently using this line of code: canvas.drawBitmap(bitmap, posX, posY, paint); and I think using a matrix for rotation is the best option? The problem is that the line of code, posted above, doesn't take a matrix but a position. There is also a similar line of code: canvas.drawBitmap(bitmap, matrix, paint); This one takes a matrix but not a position. How should I do

scaling around mid point of two fingers in android

我是研究僧i 提交于 2019-12-07 20:18:30
问题 I have a HorizontalScrollView in which there are multiple views inside it. I have implemented pinch zoom gesture in which multiple views, which are between my two fingers, are scaled. But I am facing one glitch. When I am doing pinch zoom, the mid point of pinch zoom is moving but for user experience I want this point to be remain fixed and other things should adjust itself while scaling so that mid point remains static. Can someone tell me how to do it. onDraw() method of custom view is Rect

How to use onDraw(Canvas) to obtain a bitmap snapshot of the WebView(Android)

不打扰是莪最后的温柔 提交于 2019-12-07 17:45:18
问题 I used to use capturePicture() method to make a snapshot of my WebView. This method was deprecated in API level 19. The doc say that "Use onDraw(Canvas) to obtain a bitmap snapshot of the WebView", but I really don't know how it means. Will you please teach me how to solve the problem? 回答1: The following should work: float scale = webView.getScale(); int webViewHeight = (int)(webView.getContentHeight() * scale); Bitmap image = Bitmap.createBitmap(webView.getWidth(), webViewHeight, Config.ARGB

Live Wallpaper and extended background

大兔子大兔子 提交于 2019-12-07 17:31:53
问题 I'm trying to create a live wallpaper with an animation always centered in the current homescreen page, without loosing the extended background. What I'm doing right now is to draw my custom background bitmap, then draw some text on it. This is my drawframe method: final SurfaceHolder holder = getSurfaceHolder(); Canvas canvas = null; try { canvas = holder.lockCanvas(); if (canvas != null) { if(mBackgroundBitmap != null) { canvas.drawBitmap(mBackgroundBitmap, 0, 0, null); } else { canvas

How to make EditText Clickable on canvas?

守給你的承諾、 提交于 2019-12-07 17:29:25
i want to place edit text on tap on canvas. i want to take input from user and set that edit text to canvas. here is my code: @Override protected void onDraw(Canvas canvas) { for (Point point : points) { LinearLayout lL = new LinearLayout(getContext()); EditText editTextView = new EditText(getContext()); editTextView.setFocusableInTouchMode(true); editTextView.setFocusable(false); editTextView.setClickable(true); editTextView.setText("sadsdadadadadsadasds"); editTextView.setVisibility(View.VISIBLE); lL.addView(editTextView); lL.setDrawingCacheEnabled(true); lL.measure(canvas.getWidth(), canvas

Android triangle custom buttons

血红的双手。 提交于 2019-12-07 17:25:02
问题 I want to make 2 diagonal triangle buttons like in this question. How can I achieve this? Should I make a drawable xml with a rectangle and rotate it somehow? Should I make an image and make it clickable only on the triangle parts with the help of mathematics? 回答1: package com.example.buttonsView; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.graphics.Path.FillType;

View does not fit the canvas on canvas scale

柔情痞子 提交于 2019-12-07 15:22:11
问题 When I'm trying to scale my canvas to a draw SCALED view, my view is actually scaled, but view is getting clipped. (probably because of its layout parameters?) public void onDraw(Canvas canvas) { canvas.scale(2f, 2f); view.draw(canvas); } simple image: image after new onDraw called, for example when I click this button: The button should be full sized when canvas is scaled. Do you have any ideas how to solve it? p.s. call of view.invalidate(); view.requestLayout(); doesn't help. I'm using

Android, drawing from the main activity

梦想与她 提交于 2019-12-07 13:08:01
问题 I have a custom view called DrawView created in the main activity. I have implemented the onDraw() method in the DrawView class and it initially draws a circle. I have then added a touch listener, so that when a user clicks, it then draws a square. I am up to the part where the user clicks and a square is drawn. I'm not to sure how to go about this. public class TestActivity extends Activity { DrawView drawing; /** Called when the activity is first created. */ @Override public void onCreate