After a long search and hit and trial, I found solution to this problem, Hope it will help others- This problem got solved, when I defined my circle in the xml file instead of creating it by code. Add this file, say empty_circle.xml and write this- <?xml version="1.0" encoding="UTF-8"?> <shape...
android,svg,android-canvas,android-drawable
You could render the SVG to a Picture, and then render that directly to the Canvas, with something along the lines of: public Bitmap renderToBitmap(SVG svg, int requiredWidth){ if(requiredWidth < 1) requiredWidth = (int)svg.getIntrinsicWidth(); float scaleFactor = (float)requiredWidth / (float)svg.getIntrinsicWidth(); int adjustedHeight = (int)(scaleFactor * svg.getIntrinsicHeight()); Bitmap bitmap = Bitmap.createBitmap(requiredWidth,...
based on your provide width and height of your button in layout. I use translation to do that. See the below code and the ugly Image for explain @@! LinearLayout nodesImages = (LinearLayout) findViewById(R.id.nodesImages); View v = new View(this); //this, because I write this code in the Activity class //yah,...
android,bitmap,rotation,android-canvas,ondraw
So ideal way to solve this problem is translate matrix before rotation and translate it back. Code example: Matrix m = new Matrix(); float px = getWidth()/2; float py = getHeight()/2; m.postTranslate(-bitmap.getWidth()/2, -bitmap.getHeight()/2); m.postRotate(angle); m.postTranslate(px, py); canvas.drawBitmap(bitmap, m, null); ...
android,android-canvas,android-bitmap
You calculated your second destination rectangle wrong Instead of dst1.set(fruit1Bitmap.getWidth() , 0, this.getWidth()/2, this.getHeight()/2); It should be something like: dst1.set(fruit1Bitmap.getWidth(), 0, fruit1Bitmap.getWidth() + fruit2Bitmap.getWidth(), this.getHeight()/2); Watch out for your right coordinate. This will draw the second fruit next to the first, possibly cropping it if it's too large. If...
android,bitmap,android-canvas,collision-detection
you have to use range in conditions. It may happen that your speed of moving objects is not 1. so in that case this condition never satisfy. suppose you have 2 objects then source and dest then condition will be as below: // use below condition for x if(source.x >=dest.x...
android,sprite,android-canvas,movement,gravity
I have found another solution. This one works well. y= y-(gravity * game.getResources().getDisplayMetrics().density); ...
Yayyyy!! I figured it out! In onDraw(Canvas canvas): Old code: canvas.scale((float) width, (float) height); New Code: // Scale square, so nothing gets stretched or squished canvas.scale((float) width, (float) width); // Crops the canvas canvas.clipRect(0f, 0f, 1f, .33f); Then I just make sure that all my rects are only using the...
android,xml,android-layout,android-canvas,android-custom-view
pskink is totally right, you set a padding to your "base" linearlayout your plot view so when you call getX() it returns you position of plotview in its parent layout (your base linearlayout) landmark (something corresponding to 16dp). Then when you draw a circle you set circle center in plotview...
android,graphics,android-canvas,cyanogenmod
If targetSdkVersion is 14 (Ice Cream Sandwich) or higher then hardware acceleration is enabled by default for the whole app. Unfortunately Canvas.drawPicture() is not supported if hardware acceleration is enabled. There are two way to fix this: Add android:hardwareAccelerated="false" to the application tag in your AndroidManifest.xml. This will disable hardware...
I don't think it's a software bug. My guess would be that that's the way the display is rendering colors.
Your bitmap is black because you didn't draw anything on it. To have some drawing in the bitmap you must indeed create it with this call : bitmap = Bitmap.createBitmap(getDrawingCache()); Then you have a stackoverflow exception simply because : getDrawingCache() call onDraw(Canvas) onDraw(Canvas) call getDrawnMessage(Canvas canvas) getDrawnMessage(Canvas canvas) call getDrawingCache()...
android,android-layout,android-canvas
Use 'Canvas.clipPath' For Example: Path pathA = new Path(); pathA.addCircle(xCenterA, yCenterA, radiusA, Direction.CW); Path pathB = new Path(); pathB.addCircle(xCenterB, yCenterB, radiusB, Direction.CW); canvas.clipPath(pathA); canvas.clipPath(pathB, Region.Op.DIFFERENCE); ...
Try setting a background color on your views. setBackgroundColor(Color.TRANSPARENT);. There is an optimization that it won't draw views that it thinks won't actually draw.
android,persistence,android-canvas
A Boolean array that tracks the touch state of each rectangle would do the trick. I can't see the external code, but this could be an additional field in your GameView class, and updated appropriately in your handleTouches method. A perhaps less efficient, less elegant solution would be to just...
You can use canvas.drawPoint(): To draw something, you need 4 basic components: A Bitmap to hold the pixels, a Canvas to host the draw calls (writing into the bitmap), a drawing primitive (e.g. Rect, Path, text, Bitmap), and a paint (to describe the colors and styles for the drawing). For...
android,canvas,bitmap,android-canvas,android-bitmap
You cannot do that directly -- calling draw(Canvas) on a view will cause that View to perform its drawing commands into the canvas. So in your case that would draw the TextView onto the Canvas you provided (not the other way around). If you needed to do so, you could...
It all depends on the kind of game you want to make. If you are making a grid based game, ImageViews could be more useful. However, almost no one makes Android games using layouts. Most people choose to use SurfaceView because it allows much more to be done, and in...
android,colors,background,android-canvas
Modify the layout as below: The issues is due to paddings it is not filling totally <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/layout1" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.simmaro.pruebas_canvas_2.MainActivity" > </RelativeLayout> ...
android,android-layout,android-fragments,android-linearlayout,android-canvas
Use some fake layouts and set the visibility to invisible. This should do the trick. <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res/com.example.dd" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:orientation="vertical" > <LinearLayout android:id="@+id/LinearLayout02" android:layout_width="fill_parent"...
android,android-canvas,android-imageview,android-view,android-drawable
Answer updated with zoom enable/disable and drawableview activity_main.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <Button android:id="@+id/enable_zoom" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="disable zoom"/> <com.rbt.zoomdraw.CustomImageView android:id="@+id/zoom_iv"...
Summarizing the comments: There are at least two implementations of the drawing functions, one purely in software (the Skia library), and one that uses the GPU when hardware acceleration is enabled. The Skia implementation is written in C++, not Java. Because it has to take into account Paint features like...
Do not increase start parameter. canvas.drawText(characterToString, x, m * height + y, foreground); ...
android,bitmap,drawing,android-canvas,android-custom-view
On the assumption you want to save the file to the devices storage, here is the solution i use... Add permission to manifest: <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> Here is how I am doing it: // Variables i needed private String mFileName; private Bitmap mBitmap; // apply this listener to your button private...
android,android-canvas,drawrect
Here is some code I did pretty fast that ought to help you out & you should be able to optimize int squareSize = 30; int offset = 16; // top left canvas.drawRect(offset, offset, offset+squareSize, offset+squareSize, paint); // top right canvas.drawRect(getWidth() - offset - squareSize, offset, getWidth() - offset ,...
java,android,text,android-canvas,draw
First, you need Paint Paint paint = new Paint(); // your paint settings such as stroke thickness and such Then, rotate your canvas canvas.rotate(yourTextAngle, originX, originY); Then, you draw your text canvas.drawText("Your text", originX, originY, paint); The text should be drawn vertically based on the angle you supplied. Then if...
android,view,android-canvas,draw,surfaceview
If you want to use Canvas, you are increasingly better off with a custom View, rather than a SurfaceView. The simple reason is that Canvas rendering on a View can be hardware accelerated, while Canvas rendering on a SurfaceView's surface is always done in software (still true as of Android...
You're adding DrawView with LayoutParams.WRAP_CONTENT, which means the system needs to ask the view its width and height. You should implement onMeasure() for that. But I've never done that so don't know the details. Another way is to just use LayoutParams.MATCH_PARENT and draw your stuff in onDraw() centered yourself. In...
android,android-edittext,android-canvas
Instead of using getLineCount(), maybe you could do something like this: private int getDrawableLineCount() { return getMeasuredHeight() % getLineHeight(); } The line height may need adjusting, but that should get you started....
android,android-canvas,surfaceview
You need to set zOrder in order to handle ordering of the view drawn on SurfaceView. Try setting setZOrderOnTop for your view : transparentView.setZOrderOnTop(true); Hope it helps ツ...
java,c#,android,bitmap,android-canvas
I found the solution using Matrix for set location and scale x,y Bitmap image1=BitmapUtils.decodeBase64(Lie.GeFondo().GetImagen()); Bitmap image2=BitmapUtils.getResizedBitmap(BitmapUtils.decodeBase64(Utilidades.getImagenTomadabase64()),Foto.GetTamano().GetWidth(),Foto.GetTamano().GeHeight()); Bitmap image3=BitmapUtils.getResizedBitmap(BitmapUtils.decodeBase64(Lie.GetBanner().GetImagen()),Lie.GetBanner().GetTamano().GetWidth(),Lie.GetBanner().GetTamano().GeHeight()); Bitmap result =...
android,performance,opengl-es,android-canvas
It looks like you want to offload some heavy pixel manipulations to the GPU. On Android, you have two major options: OpenCL, but OpenCL support on Android is cumbersome RenderScript But don't underestimate the power that a CPU has, when you use vectorization instructions well. This might require hand-coding the...
I played with this for some time and I realized that the solution is as simple as switching the two commands in onDraw. Instead of canvas.drawBitmap(bitmap, 0, 0, null); canvas.drawPath(path, paint); use canvas.drawPath(path, paint); canvas.drawBitmap(bitmap, 0, 0, null); Drawing the bitmap last solves the problem. It is still too dark...
Threads! However the handler is not the root of your problem judging by how slow your animation is running and how choppy the fast one is, you are probably using a canvas tied into an ImageView? This is not very fast at all. You should look into using a SurfaceView...
android,coordinates,android-canvas
myView.setOnTouchListener(new OnTouchListener(){ @Override public boolean onTouch(View v, MotionEvent event){ Log.d("coords", event.getX() + " : " + event.getY(); if(..){ // Do stuff.. } } }); ...
android,android-layout,android-canvas
Using canvas.getClipBounds() should give the appropriate sizes, even if the canvas width and height are actually larger.
You can draw a border using Paint.STYLE.STROKE. You need to do two separate calls to drawCircle(): paint.setStyle(Paint.Style.FILL); paint.setColor(Color.parseColor("#BAB399")); // set fill color canvas.drawCircle(sbmp.getWidth() / 2+0.7f, sbmp.getHeight() / 2+0.7f, sbmp.getWidth() / 2+0.1f, paint); paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(10); // set stroke width paint.setColor(Color.parseColor("#ffffff")); // set stroke color canvas.drawCircle(sbmp.getWidth() / 2+0.7f, sbmp.getHeight() / 2+0.7f, sbmp.getWidth()...
java,android,android-layout,android-activity,android-canvas
here is full fledged answer it is perfect for you, <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="50dp" android:orientation="horizontal" > <View android:layout_width="5dp" android:layout_height="wrap_content" android:background="#CC3333" /> <RelativeLayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="#808080" >...
android,android-canvas,paint,android-custom-view,android-ui
Since color is actually an integer, you can easily convert it to hexadecimal with String.format. It seems you want to ignore the alpha channel so you can filter it out: String.format("#%06X", color & 0xffffff); ...
android,android-canvas,android-imageview
Comparing View and Canvas is comparing apples and oranges. Anything that goes onto the screen is in a View. A Canvas just provides a way to draw things; it's used internally by all View types, including ImageView. If you implement a custom View type, a Canvas is the argument to...
Is not what I wanted to achieve but is a workaround and maybe is helpful for somebody, I am putting in invisible the second canvas, and then when is ready, I put it visible back. @Override public void lock(String message) { runOnUiThread(new Runnable() { @Override public void run() { canvasFront.setReadyToDraw(false);...
Use below code private Bitmap overlay(Bitmap bmp1, Bitmap bmp2) { Bitmap bmOverlay = Bitmap.createBitmap(bmp1.getWidth(), bmp1.getHeight(), bmp1.getConfig()); Canvas canvas = new Canvas(bmOverlay); canvas.drawBitmap(bmp1, new Matrix(), null); canvas.drawBitmap(bmp2, x,y, null); return bmOverlay; } Where x and y are actual positions where you have to draw the overlay bitmap....
android,android-canvas,surfaceview,android-bitmap
Change your calculation from this: canvasWidth*(memoryManiaHeight/memoryManiaWidth) to this: (canvasWidth*memoryManiaHeight)/memoryManiaWidth If you evaluate (memoryManiaHeight/memoryManiaWidth) first then it will evaluate to zero due to integer division....
android-canvas,android-view,objectanimator
I somehow figured it out how to achieve it. I, however could not directly draw a canvas line with animation though but found out a work around and that actually worked for me. I used a horizontal progress bar instead with a negligible height which will look like a line...
android,performance,animation,android-canvas
You are not using a Path here at all, so do not worry about predefined paths. You do not need to optimize your code, unless you see it becomes slow, which should not be the case. One possible optimization is if you draw many times a circle of the same...
android,android-canvas,android-view,android-custom-view,android-drawable
You should possibly use SurfaceView instead. It is more advanced compared to ImageView. Refer to this for drawing: http://examples.javacodegeeks.com/android/core/ui/surfaceview/android-surfaceview-example/ This is for zoom: http://android-innovation.blogspot.co.nz/2013/07/how-to-implement-pinch-and-pan-zoom-on.html...
java,android,animation,android-canvas,ondraw
Yes. Calling postInvalidate sets up the canvas to the screen and passes it to the onDraw function, as well as various other pieces of logic. Calling onDraw directly only makes sense if you want to draw a view to somewhere other than the screen. In addition, postInvalidate will cause it...
This should get you started. //Path for a rounded rectangle. path = new Path(); path.moveTo(rx, 0); path.lineTo(width - rx, 0); path.quadTo(width, 0, width,ry); path.lineTo(width, height-ry); path.quadTo(width, height, width-rx,height); path.lineTo(rx, height); path.quadTo(0,height, 0, height-ry); path.lineTo(0,ry); path.quadTo(0, 0, rx, 0); //valid APIs less than 21. float centerX = (x+width)/2; float centerY =...
Use customview by extending the view class to achieve this: Let's call your custom class say LineView. So this is what Line should look like. LineView.java import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.view.View; public class LineView extends View { Paint paint = new Paint(); public LineView(Context context,...
There are 3 ways you could accomplish this off the top of my head. The first is to define the second RecfF as 50 pixels further to the right. new RectF(50, 0, 100, 50); The next is to translate the canvas before drawing the second. mRedRect = new RectF(0, 0,...
android,android-animation,android-canvas,android-view
I suddenly started to look into object animators. The solution is to use one that animates from my current percentage to the new percentage. The result is exactly what I wanted. Here is the updated view: public class ProgressDownload extends View { private static final String LOG_TAG = ProgressDownload.class.getSimpleName(); private...
The equation of line is not needed. If you want to divide the line into k equal parts, you will need k-1 points. ...
android,android-studio,android-canvas,android-view
The drawOval() method that you are using from canvas was added in API 21. public void drawOval (float left, float top, float right, float bottom, Paint paint) - API 21. You should try using the drawOval() with RectF parameter, instead. public void drawOval (RectF oval, Paint paint) - API 1...
android,android-canvas,android-view,android-drawable
You should keep track of the lines within a Path component. Add to the path when you have a new line to draw. Then you can draw the path within the onDraw() or clear the path when you need to for whatever reason. Path | Android Developers One example might...
android,android-canvas,surfaceview
I think there is no other ways to draw instead of canvas. You can use SurfaceView to draw any shape even a cricle also. First you ahev to get SurfaceHolder object and using that you can draw anything. Yo can follow these links- first second
android,android-layout,android-canvas,spannablestring
Setting setTextAlign(Paint.Align.CENTER) on TextPaint might be interfering with your spans. Instead, use Layout.Alignment.CENTER on the StaticLayout which should center the text as a whole. mCenterTextLayout = new StaticLayout(mText, textPaint, (int) maxTextWidth, Layout.Alignment.ALIGN_CENTER, 0.85f, 0, false); ...
What's the point of undoing what we just did! You're not, though. If you're just going off the words, it does sound like that's what might happen, but it actually isn't. Think of it like this: You have a series of really complex translations and rotations you want to...
This is a trigonometry problem Understand that in your original non-rotated canvas, the point is at a certain angle and a certain length from center... Polar coordinates. Then when the canvas is rotated, it is still at that same location, relative to the canvas, so it's absolute position has the...
android,math,canvas,android-canvas,ondraw
You can calculate its rotation using sin and cos. Lets assume that you have zero point A and want to rotate it to point B which is rotated for 30°. Something like this: Basically new point is at (cx+x,cy+y). In this particular case definition of sin and cos would be...
I believe you are looking for canvas.drawBitmap
java,android,bitmap,android-canvas
You could check if hardware acceleration is used on your tablet. https://developer.android.com/guide/topics/graphics/hardware-accel.html
do it this way Rect rs = new Rect(); Rect rd = new Rect(); rs.left = rs.top = 0; rs.right = 480; rs.bottom = 800; <calculate destination rectangle from device size> canvas.drawBitmap(myBitmap, rs, rd, null); You can also scale and translate (shift) the entire canvas canvas.scale(float scaleX, float scaleY); canvas.translate(float...
android,android-canvas,android-recyclerview
Use invalidate() method for calling onDraw method. @Override public void onBindViewHolder(ViewHolder holder, int position) { holder.viewx.setText(mopenPrice.get(position)); if(condition){ holder.viewx.setCustomColor(Color.GREEN); holder.viewx.invalidate(); } } public class MyView extends View { private int color = Color.WHITE; public MyView(Context cxt, AttributeSet attrs) { super(cxt, attrs); setMinimumHeight(100); setMinimumWidth(100); } @Override protected void onDraw(Canvas cv) { cv.drawColor(color);...
You can make a setCircleColor to change the color of the circle and call invalidate that will call the View onDraw method. You can also check for invalidate(Drawable drawable). public class MyCustomView extends View { MyCustomView myView; private Paint myCircle; public MyCustomView(Context context){ super(context); initView(); } private void initView(){ myView...
You can call public void drawBitmap (Bitmap bitmap, Rect src, RectF dst, Paint paint) for this function (Android Doc). The code below should accomplish what you are trying to do: canvas.drawBitmap(bitmap, null, new RectF(0, 0, canvasWidth, canvasHeight), null); ...
You don't really can get the control on when the onDraw will be called: when a view is invalidate then the onDraw will be called at some point in future. There is a fundamental design flaw in your code: the position of player is modified during the execution of the...
java,android,android-layout,android-canvas,android-wear
In your onCreate() do Matrix matrix = new Matrix(); And in onDraw float angle = (float) (System.currentTimeMillis() % ROTATE_TIME_MILLIS) / ROTATE_TIME_MILLIS * 360; matrix.reset(); matrix.postTranslate(-source.getWidth() / 2, -source.getHeight() / 2); matrix.postRotate(angle); matrix.postTranslate(centerX, centerY) canvas.drawBitmap(source, matrix, null); invalidate(); // Cause a re-draw ROTATE_TIME_MILLIS is the full circle time, e.g. 2000 is...
android,canvas,android-canvas,appcelerator
Download and recompile the module and it works fine... hope all is well, ping me if you run into additional issues. ...
@Override public void draw(Canvas canvas) { float size = Math.min(getWidth(),getHeight()); paint.setStrokeWidth(size/4); paint.setStyle(Paint.Style.STROKE); final RectF oval = new RectF(0, 0, getWidth(), getHeight()); oval.inset(size/8,size/8); paint.setColor(Color.RED); Path redPath = new Path(); redPath.arcTo(oval, 0, 120, true); canvas.drawPath(redPath, paint); paint.setColor(Color.GREEN); Path greenPath = new Path(); greenPath.arcTo(oval, 120, 120, true); canvas.drawPath(greenPath, paint); paint.setColor(Color.BLUE); Path bluePath =...
java,android,graphics,android-canvas,android-bitmap
Draw with a Bitmap: Bitmap mDrawBitmap; Canvas mBitmapCanvas; Paint mDrawPaint = new Paint(); @Override public void onDraw(Canvas canvas) { if (mDrawBitmap == null) { mDrawBitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888); mBitmapCanvas = new Canvas(mDrawBitmap); } // draw on the btimapCanvas //... and more mBitmapCanvas.drawWhatever(...); // after drawing with the bitmapcanvas, //all...
java,android,android-canvas,android-drawable
What if you create clones of the Drawable and modify each as required? See Flavio's answer here: Android: Cloning a drawable in order to make a StateListDrawable with filters
java,android,android-canvas,clock
You can rotate the line (startX, startY) and (endX, endY) individually or you can rotate the canvas itself (which I think it is easier). Using your example: Paint myPaint = new Paint(); myPaint.setColor(Color.rgb(0, 0, 0)); myPaint.setStrokeWidth(10); canvas.drawCircle(50, 100, 50, myPaint); Paint p = new Paint(); p.setColor(Color.rgb(250, 250, 250)); p.setStrokeWidth(2); float...
android,android-fragments,canvas,android-canvas
(Just to make this proper): Add the rect RelativeLayout in your fragment_show_profils.xml file and not in fragment_show_rooms.xml. :-)...
android,android-ndk,android-webview,android-canvas,android-5.0-lollipop
The issue came from a race condition that sometimes caused my code to draw onto a Canvas that belonged to a recycled Bitmap. The crash can be reproduced with the following code: Bitmap bmp = Bitmap.createBitmap(someRelativeLayoutContainingWebView.getWidth(), someRelativeLayoutContainingWebView.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bmp); bmp.recycle(); someRelativeLayoutContainingWebView.draw(canvas); // SIGSEGV will happen here...
I fixed my problem. Actually when i rotate canvas the event.getX() and event.getY() were not map to current rotation of matrix so by adding this line in mMatrix.invert(tempMatrix); in OnDraw() and also map current x,y in OnTouch() by adding this in OnTouch() method . float[] coords = new float[] {...
java,android,android-canvas,surfaceview
Move the unlockCanvasAndPost() inside the if (myCanvas != null) { statement. My guess is lockCanvas() is returning null, and you're attempting to unlock a null reference. Looking at the source code, the test for "is it the same" comes before the test for "is it locked at all" -- and...
I do not know It will work for you or not but try this way,because I have button,add custom item.. <item android:id="@+id/badge" android:actionLayout="@layout/feed_update_count" android:icon="@drawable/shape_notification" android:showAsAction="always"> </item> Button <Button xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/notif_count" android:layout_width="wrap_content" android:layout_height="wrap_content" android:minWidth="32dp" android:minHeight="32dp"...
The problem is the SurfaceView is not being rendered with 32 bit colors. You will need to get the SurfaceHolder for the SurfaceView. This can be achieved through getHolder() on the view itself. Then just put it into 32 bit mode with: getHolder().setFormat(PixelFormat.RGBA_8888);...
Add some more code after the line canvas.drawColor(Color.TRANSPARENT); or change the color. Painting a transparent color will show nothing different on the screen. Also, you are missing the super call to onDraw. Here is the android docs for Canvas where you will find many methods for drawing paths, shapes and...
android,android-canvas,surfaceview
Sort of. The SurfaceView's Surface uses multiple buffers. If it's double-buffered, and you don't clear the screen every frame, then you'll have the rendering from all the odd-numbered frames in one buffer, and all the even-numbered frames in the other. Every time you draw a new frame, it'll flip to...
java,android,bitmap,android-canvas
If you are facing a similar problem to mine then check out Rebound, courtesy of pskink. It solved my issues.
android,imageview,android-canvas
I was looking for the best approach for a long time. Your solution is pretty heavy and doesn't work well with animations. The clipPath approach doesn't use antialiasing and doesn't work with hardware acceleration on certain versions of Android (4.0 and 4.1?). Seems like the best approach (animation friendly, antialiased,...
java,android,animation,android-canvas,circle
Call this.invalidate() to force redraw on next frame: private int x = -1; private int y = -1; private int r = -1; private int stepsLeft = 300; @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (x < 0) { // generate new circle int[] xy = generateXY(); x =...
android,android-canvas,android-imageview
You can use canvas.translate(x,y); and then draw. Here is some example code: //Clear the canvas otherwise previous drawing will still be there canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); //save the current default drawing position canvas.save(); canvas.translate(value,0); canvas.drawBitmap(starBitmap, 0, 0, null); //restore the default drawing position, otherwise will translate from the last traslated to position...
android,android-intent,bitmap,android-canvas
The attachment is not readable by other apps because you are saving it to getFilesDir(). Simply change getFilesDir() to Environment.getExternalStorageDir() and other apps will be able to handle the saved image. This also requires you to add the following permission in your AndroidManifest: <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> I don't know why...
android,android-canvas,android-gridview
Your error is that you never called super.onDraw(canvas) @Override public void onDraw(Canvas canvas) { super.onDraw(canvas); //<== this line is needed to begin drawing on the canvas paint.setColor(Color.RED); paint.setStyle(Paint.Style.FILL); paint.setStrokeWidth(1); canvas.drawRect(0, 0, canvas.getWidth()-1, canvas.getHeight()-1, paint); } you need to explicitly set the derived View dimensions using setMinimumWidth() and setMinimumHeight()...
android,android-layout,android-canvas,android-view,android-styles
Well, the easiest way to do it would be to change Paint object's color in on touch method of your custom view. You could do it more less like this: @Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()){ case MotionEvent.ACTION_DOWN: paint.setColor(mPressedColor); invalidate(); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: paint.setColor(mNormalColor); invalidate(); break;...
Before you draw anything on the canvas: //clear the canvas canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); And now your canvas is clear and you can draw your character. If your onDraw method was in an expanded view class and was triggered by you calling invalidate(), then the canvas would automatically clear itself. But you...
android,canvas,bitmap,android-canvas,opacity
The ball shapes are where each line segment overlaps the previous one. You can fix this by using a second image overlaid on top of the image that you are editing. Initialize the overlay image to completely transparent and make it the same size as the image you are editing....
android,android-canvas,paint,text-size,drawbitmap
The problem with density was the size of the bitmap itself, while it's small, the printed texts cannot be smooth! Text size: paint.setTextSize(fontSize); density is the same problem like smoothing, so just make it bigger. type: paint.setTypeface(Typeface.create(Typeface.DEFAULT_BOLD, Typeface.BOLD)); color: paint.setColor(Color.BLACK); background color: canvas.drawColor(Color.WHITE); ...