android-canvas

Plot Multiple Charts in one in MPAndroidChart

折月煮酒 提交于 2019-11-28 08:17:37
问题 I have to plot two different dataSets in a single graph. DataSet-1 String[] xAxisOne = new String[] { "0", "1", "2", "3", "4", "5", "6" }; float[] dataInput = { 1f, 2f, 3f, 4f, 5f, 6f, 7f }; DataSet-2 String[] xAxisTwo = new String[] { "0", "2", "4", "5", "6", "8", "9" }; float[] dataIn = { 3f, 4f, 5f, 6f, 7f, 8f, 9f }; In the above data, DataSet-1 is reference by which graph is created. DataSet-2 has to be plotted in the same with different set of X-Values {xAxisTwo} . In existing

How can I get the bitmap of the canvas I get in onDraw?

核能气质少年 提交于 2019-11-28 07:19:05
问题 How can I create the bitmap from the canvas of custom view. 回答1: There is no way to extract the Bitmap out of a Canvas . The only way you can access it is to pass it yourself when creating the canvas like this new Canvas(myBitmap) and keep the reference. EDIT2: see @Alex comment blow - the approach of passing a Bitmap to the Canvas does not seem to work for more recent versions of Android. EDIT : If you don't create the Canvas yourself, you could create a screen-sized Bitmap (or whatever size

Drawing a filled rectangle with a border in android

↘锁芯ラ 提交于 2019-11-28 07:09:29
Is there any way in Android to draw a filled rectangle with say a black border. My problem is that the canvas.draw() takes one paint object, and to my knowledge the paint object can't have a different color for the fill and the stroke. Is there a way around this? You draw a rectangle with the color of the border and the size of the rectangle plus the border, you change the color of the paint and draw again the rectangle with the normal size. Try paint. setStyle (Paint.Style. FILL ) and paint. setStyle (Paint.Style. STROKE ). Paint paint = new Paint(); Rect r = new Rect(10, 10, 200, 100);

Canvas not displaying all drawn parts in Custom View?

让人想犯罪 __ 提交于 2019-11-28 06:37:18
I'm working on a custom view for an android application, similar to the Analog Gauge sample code available from Mind the Robot . Running the code from listed site, I get see this on my screen: (Motorola Droid, 2.2.3), (Emulator, 4.0.3) (Xoom, 4.0.3)(Other phone, 4.0.3) The hand is missing! The drawing calls are being made (I can see them in logcat), but the canvas elements the calls draw are invisible. It's not API level dependent , though; if I import it the right way into a project, it will hand will show up when I run it on the Xoom. But, when I move the files to a different project folder

convert view into bitmap [duplicate]

狂风中的少年 提交于 2019-11-28 06:35:22
Possible Duplicate: Converting a view to Bitmap without displaying it in Android? I am trying to convert the view into bitmap from following reference link link text Now the problem is how can i get the bitmap that is being converted from view only. in the example author has used relativelayout.dispatchDraw(c) but this line is giving me compile time error i.e. The method dispatchDraw(Canvas) from the type ViewGroup is not visible Here is my code and i have written the following code inside onCreate function Canvas c=null; //Create Layout RelativeLayout relativeView ; RelativeLayout

Android Drawing bitmap and button on canvas by X Y Positions

杀马特。学长 韩版系。学妹 提交于 2019-11-28 06:35:18
问题 i'm new into android and i have some problems with my app. Any help will be appreciated :) I have drawing bitmap on canvas by xpositon and ypostion by sensors (when i'm moving my phone, bitmaps are moving ) I need to create moving clickable button on center of my bitmaps and when i click them i will go to next activity . Bitmaps are drawing perfectly but idont know how to draw buttons on them, buttons that will be moving with my bitmap by the same values of x and y. How i can do that? This is

Android transparent canvas (surfaceview)

限于喜欢 提交于 2019-11-28 06:06:08
I've got a panel which is placed on top of another view via a relativelayout. I would like to give this panel a transparent background, but didn't find the correct way to do this after searching for some hours. When I set the alpha back to 0 I end up with a black background. Hopefully someone here can help me with this. Thanks a lot! The panel is drawn via this code: import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.util.AttributeSet; import android.view.SurfaceHolder; import android.view.SurfaceView; public class Panel extends

Adding a round frame circle on rounded bitmap

Deadly 提交于 2019-11-28 06:04:39
Im trying to create a round frame around my bitmap! With this code im able to make my bitmap round: public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) { Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap .getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff4242DB; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); final float roundPx = bitmap.getWidth()/2; paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas

Android: Adding Background on a Custom TextView class

淺唱寂寞╮ 提交于 2019-11-28 05:40:17
问题 I want to have a background of my TextView class, but I don't know how. I try to use the onDraw method on the class but it is not working. Here is my code for my custom TextView class. public class Balls extends TextView{ public Balls(Context context) { super(context); // TODO Auto-generated constructor stub this.setText("ball"); } protected void onDraw(Canvas canvas) { super.onDraw(canvas); Paint paint = new Paint(); paint.setColor(Color.RED); canvas.drawCircle(50, 50,30, paint); }} Any idea

How to draw a path on an Android canvas with animation?

末鹿安然 提交于 2019-11-28 04:23:37
I'm making an Android app and I've got a tricky thing to do. I need to draw a path on a canvas but the drawing should be animated (ie. drawing point after point with a slight delay). Is it possible to make something like this using Android SDK? If not, how could I produce this effect? Try this code, I used it to draw a heartbeat using Path & Canvas : public class TestActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new HeartbeatView(this)); } public static