android-canvas

How to preallocate RadialGradient?

岁酱吖の 提交于 2019-12-11 08:17:33
问题 I'm drawing some circles on a canvas. I want to apply a radial gradient to each of this circle. I'm currently allocating a new gradient for each circle, but i'm guessing this not a very good idea. protected void onDraw(Canvas canvas) { int radius = 6; int cx = radius; int cy = radius ; for(int i = 0; i < nbPage; i++) { if(i % 12 == 0 && i > 0) { cx = radius; cy += 20; } RadialGradient gradient = new RadialGradient(cx, cy, radius, 0xFFFFFFFF, 0xFF000000, android.graphics.Shader.TileMode.CLAMP)

How to redraw SurfaceView using invalidate() metod?

南楼画角 提交于 2019-12-11 06:45:49
问题 I have a class GameBoard which extends SurfaceView . Inside I have an OnDraw method: @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int size = getWidth()/8; canvasSize = size; pawnBitmap[0] = bigPawn; pawnBitmap[1] = smallPawn; float left_distance; float top_distance; for(int j = 0; j < 10; j++){ for (int i =0; i < 4; i++){ left_distance = i*size+(float)50; top_distance = j*size+(float)10; canvas.drawBitmap(pawnBitmap[0], left_distance, top_distance, paint); canvas

Tablet - Get Drawable Screen Resolution, Not Total Screen Resolution

本小妞迷上赌 提交于 2019-12-11 05:23:21
问题 With tablets and some phones running 4.0 there are on screen controls. I am developing a full screen canvas-based game. I adjust my canvas to fit the screen size with a matrix. On any device that has on screen buttons my app currently draws part of the games' controls under those buttons. Is there a way to determine the drawable screen resolution, IE the resolution minus any onscreen buttons? EDIT: This is the way I'm testing for resolution Display display = ((Activity) gameContext)

Drawing two shapes with transparency in Android/Java

别等时光非礼了梦想. 提交于 2019-12-11 05:05:47
问题 I'm drawing two shapes in Android using paint and canvas. I applied transparency to the paint color, but now when the two shapes (same color) intersect the intersecting section comes out darker. Does anyone know how to accomplish this? Here is a quick look at my paint code (which... should be the only object necessary to complete this I imagine). Paint paint = new Paint(); paint.setColor(color); paint.setAntiAlias(true); paint.setStrokeWidth(strokeWidth); paint.setStrokeJoin(Paint.Join.ROUND)

Why is my cardview not being drawn onto canvas?

99封情书 提交于 2019-12-11 04:52:06
问题 I'm trying to draw a cardview onto a pdf its canvas. Unfortunately the cardview is not drawn. However some test text is drawn. Why is my carview not drawn? Code: // start a page PdfDocument.Page page = document.startPage(pageInfo); Canvas c = page.getCanvas(); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(1000, 50); CardView card = new CardView(this); card.setLayoutParams(params); card.setRadius(4f); Bitmap cardBitmap = Utils.loadBitmapFromView(card); c.drawText(

How to draw with multiple fingers in canvas

霸气de小男生 提交于 2019-12-11 04:47:33
问题 I am using android Canvas class from creating drawing application. This is my first attempt to work with Canvas class. So far the code that i used is working fine and the drawing is working fine. But what i realized in this code is that, it allow user to draw with one finger only, i mean to say if the user used more then one finger to draw on canvas it doesn't allow the user to draw with multiple finger. I go through several documentation regarding multiple touch event but failed to implement

How to draw the contour of a union of Path

萝らか妹 提交于 2019-12-11 03:24:09
问题 Hello i have a pack of Hexagon Path and a want to draw the contour(border) of the union of those Path. I thought of using Region, to union the Path together then get the border resulting Path with getBoundaryPath(), but it draw nothing. So can someone tell me how can I have the contour(border) of the union of all my Path objects ? @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // if (pmBack != null) { // canvas.drawBitmap(pmBack, new Matrix(), paint); // } if (mCells !

android: how to implement canvas draws into a exist view in XML

感情迁移 提交于 2019-12-11 03:13:14
问题 I have a XML file in my program like: <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1"> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:background="#ef3" android:id="@+id/img01"/> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:background="#E8A2B4" android:id=

Saving Canvas in onDraw();

≡放荡痞女 提交于 2019-12-10 23:36:37
问题 I'm trying to save the Canvas object in a onDraw() method. This is because i'm using a foreach loop in the onDraw method resulting in : canvas.DrawText (textitem , x,y, textpaint); (i have to do this because im drawing the text around a masked area) what im trying now is this : @Override public void onDraw(Canvas canvas) { if (hasrun = false) { for(CustomTextViewDrawItem item : drawItemList) { canvas.drawText(item.Text, item.X, item.Y, textPaint); } if (eLabel.backgroundGradient != null) {

give space between text and underline with customview android

与世无争的帅哥 提交于 2019-12-10 23:26:19
问题 I want an underline below OPTING like below, but when i create this will the help of customview, underline appears just below opting but i want some space between text and line like image I had created a Custom view, in which a word will searched in a string if that is found, then that corresponding text will be underlined but the only thing i want is to give some space between underline and text, My class is as follows, import android.content.Context; import android.content.res.TypedArray;