android-canvas

Custom view Canvas onDraw() doesnt draw anything

喜夏-厌秋 提交于 2019-12-24 12:31:23
问题 I am trying to draw a oval using canvas, but it never gets drawn. Here is my code for the custom view. I have also used setWillNotDraw(false) still nothing gets drawn on the screen. public class Myview extends View { Paint paint; RectF rect; public Myview(Context context) { super(context); init(); setWillNotDraw(false); } public Myview(Context context, AttributeSet attrs) { super(context, attrs); init(); setWillNotDraw(false); } public Myview(Context context, AttributeSet attrs, int defStyle)

How to draw path like canvas in Android using OpenGL ES 2?

[亡魂溺海] 提交于 2019-12-24 11:14:26
问题 I have tried Canvas in Android, and I can make sketch or path by moving my finger on the screen. Now, I want to do the same thing using OpenGL 2. I'm new to OpenGL programming but I have tried several method to draw a Line using GLES20.glDrawArray(...) and a Line Shape class but still, this just make a straight line not like a free-form path i wanted just like when I use canvas. and also, if i try to draw per line segment each time ACTION_MOVE, concurrent modification exception often happens

Android: cut a part off a bitmap and scale it

橙三吉。 提交于 2019-12-24 10:48:22
问题 First I want to say, that I really read much but I didn't find exactly this problem... At the moment my code does work well. I have a bitmap, then I cut a part of my bitmap and draw this. this.card = new ImageView(this); //this is my ImageView //and my bitmap... this.bmCards = BitmapFactory.decodeResource(getResources(), R.drawable.cardgame); //and here I set the bitmap as Image of this ImageView this.card.setImageBitmap(getCard(Stapel.getCard())); the method, that is called is the following:

Size of a Canvas in a Surfaceview against real screen resolution

人盡茶涼 提交于 2019-12-24 08:07:51
问题 I am trying to use the SurfaceView and the Canvas to make some draws, in my 480x800 phone, but I do not understand how this is managed, because when I display canvas size, it show 320x533 ( while my screen is 480x800 ) I tryied to use setFixedSize() on the getHolder to reset the canvas resolution, seems to work fine, but is it a correct way to do such resize ? Another trouble is getting the touch event coordinates, while my canvas seem to be resized, to touch events are still matched against

How to invoke drag event of a custom view inside SurfaceView?

↘锁芯ラ 提交于 2019-12-24 06:48:09
问题 How can i drag a custom view inside the SurfaceView. Touch events are not dispatched to child custom view from SurfaceView or child view's onTouchEvent is not called. 回答1: Try this code public class MoveViewTouchListener implements View.OnTouchListener { private GestureDetector mGestureDetector; private View mView; public MoveViewTouchListener(View view) { mGestureDetector = new GestureDetector(view.getContext(), mGestureListener); mView = view; } @Override public boolean onTouch(View v,

How to invoke drag event of a custom view inside SurfaceView?

﹥>﹥吖頭↗ 提交于 2019-12-24 06:47:16
问题 How can i drag a custom view inside the SurfaceView. Touch events are not dispatched to child custom view from SurfaceView or child view's onTouchEvent is not called. 回答1: Try this code public class MoveViewTouchListener implements View.OnTouchListener { private GestureDetector mGestureDetector; private View mView; public MoveViewTouchListener(View view) { mGestureDetector = new GestureDetector(view.getContext(), mGestureListener); mView = view; } @Override public boolean onTouch(View v,

Draw portion of image on Canvas

♀尐吖头ヾ 提交于 2019-12-24 04:41:14
问题 I have an image of size 265x256 and I want to draw the top-left and right-bottom portion of size 16x16 at random location on Canvas Can someone please share the concept or code to do this 回答1: I think you can use Canvas method public void drawBitmap (Bitmap bitmap, Rect src, RectF dst, Paint paint) where documentation states second argument src as If the source rectangle is not null, it specifies the subset of the bitmap to draw. So you can pass the rectangle of the source bitmap that you

Creating circle in SurfaceView on button click android

こ雲淡風輕ζ 提交于 2019-12-24 04:12:26
问题 So essentially I am working on an app that creates a circle withing a SurfaceView. I want for a new circle to be generated inside the SurfaceView whenever pressing the "create" button. Each new circle would have a random speed, color, starting position along with a unique sequence number. It's easy enough to create a circle with a random color and starting position, but I was having some trouble getting the circle to draw only when I click on the create button. Whenever I try to create a

Android FingerPaint Example using Canvas, what is the offscreen Canvas?

微笑、不失礼 提交于 2019-12-24 03:12:28
问题 Hi I was reading the fingerpaint example, because I'm building a signature activity, that allows the user to draw a signature on the cellphone and then save it to SD. So far I've seen that the mPath variables holds the path that the user is currently drawing, and this path is drawn onto the screen on the onDraw(..) method by calling canvas.drawPath(mPath, mPaint); However on the example there is another canvas "mCanvas" that draws the path on the touch listener: private void touch_up() {

canvas not drawing in java android

て烟熏妆下的殇ゞ 提交于 2019-12-24 03:04:25
问题 I think the code is right, but I'm unable to find what's going wrong. Can anyone help please in figuring out what's incorrect ? Thats the activity document: package com.example.crazyeights; import android.os.Bundle; import android.app.Activity; import android.view.Menu; public class CrazyEightsActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MyView view = new MyView(this); setContentView(view); } @Override public