android-canvas

Android - Drawing on the different devices

老子叫甜甜 提交于 2019-12-06 08:43:27
In my app I create a canvas and add some bitmaps on it. The problem is that the objects are adding why touch the screen. So on one screens they appear on the middle on different the same, but their position in pixels are different. I mean that I got tablet and smartphone. When I touch one the object appear on both devices (multiplayer) but its not in the same place, because its passing the position by x and y. If someone understand what I mean, can you help me? Probably it must have something common with counting the ratio. I am guessing the problem you are having is that the screens are

How do I draw a EditText to canvas in android?

做~自己de王妃 提交于 2019-12-06 07:54:56
问题 I would like to draw EditText username = new EditText(context); to a specific spot on my canvas in protected void onDraw(Canvas canvas) { } Is it possible to draw it on the basis of x,y coordinate in my Java file without using XML layout? 回答1: Yes you can draw EditText on Canvas , Here is hint: EditText ed; . . . . . ed.setDrawingCacheEnabled(true); Bitmap b = ed.getDrawingCache(); canvas.drawBitmap(bitmap, l, t, r, b, null); You can create/initialize EditText at run time like this: EditText

How to access or translate text in Vector Drawables

隐身守侯 提交于 2019-12-06 07:49:31
问题 I have a custom view which displays a drawable and detects touches. It has a number of drawable layers, some of which contain text, for example, I have converted each SVG vector graphic into a vector drawable and want to be able to set the text to be a resource so I can substitute different translations. The SVG xml code for the 'Hello box' above :- <svg width="800" height="400" viewBox="0 0 800 400.00001" id="svg5772" version="1.1" inkscape:version="0.91 r13725" sodipodi:docname="HELLO in a

3d cube using canvas. Need a little improvement

无人久伴 提交于 2019-12-06 06:24:45
问题 I made this 3d cube using the following code Matrix mMatrix = canvas.getMatrix(); canvas.save(); camera.save(); camera.rotateY(-angle); camera.getMatrix(mMatrix); mMatrix.preTranslate(-width, 0); mMatrix.postTranslate(width, 0); canvas.concat(mMatrix); canvas.drawBitmap(bmp1, 0, 0, null); camera.restore(); canvas.restore(); camera.rotateY(90 - angle); camera.getMatrix(mMatrix); mMatrix.preTranslate(-width, 0); mMatrix.postTranslate(width2, 0); canvas.concat(mMatrix); canvas.drawBitmap(bmp2,

Android: How to draw on a Surfaceview which already is displaying a Camara Preview

本秂侑毒 提交于 2019-12-06 05:07:39
I am trying to program an application which has to display on the mobile phone's screen what is being filmed by the front camera [The application is not recording/saving anything in the memory of the phone]. Also in case a face is filmed (and detected), it has to appear sourrended by a rectangle. To do so I'm using: A Surfaceview to display what is being filmed by the front camera. A FaceDetectionListener to detect faces in the camera input. So far the application displays properly what is being filmed by the front camera. It also detects correctly faces. But I'm not able to draw the boundary

Android canvas - Drawing arc between to points and removing arc from path

筅森魡賤 提交于 2019-12-06 04:46:30
问题 In my android application, i want to provide tracing letter feature as shown in following image : Here i want to provide tracing of letter-D and for that i need to draw arc between two points when user starts moving finger on arc. Here, if user starts moving finger from start point and stops at end point then only it should draw arc between those points. And it should also show arc while moving finger on arc path.For that i have written below code.The problem i am facing is that, when ACTION

Android - User paints lines with their finger

不想你离开。 提交于 2019-12-06 04:39:47
I want to build a tool on Android where the user can paint some simple objects over a picture (eg line, circle or arrow). I started trying the line part first, and indeed I could succeed on painting it. The logic is that the user taps at one point and then drags their finger, painting the line. I use a class like this (it is based on DonGru's answer here ): public class DrawView extends View { Paint paint = new Paint(); float Sx, Sy, Lx, Ly; public DrawView(Context context, float x1, float y1, float x2, float y2) { super(context); paint.setColor(Color.RED); Sx=x1; Sy=y1; Lx=x2; Ly=y2; }

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

旧街凉风 提交于 2019-12-06 04:14:52
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; private float mLastTouchX; private float mLastTouchY; private int mActivePointerId = INVALID_POINTER_ID;

scaling around mid point of two fingers in android

China☆狼群 提交于 2019-12-06 04:08:29
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 r =new Rect(0, 0, 700, 40); public void onDraw(Canvas canvas) { float kk=mScaleFactor; //this variable

how to clear view in android?

自古美人都是妖i 提交于 2019-12-06 03:26:24
问题 I have created a simple demo application in android for drawing ,now can any one say me how can i remove view and clear screen in just one click .I have tried as below:please help me to do it....thanx in advance..! main.java package com.example.singletouch; import com.example.singletouch.R.attr; import android.os.Bundle; import android.app.Activity; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.view