ondraw

Android Monospace fonts aren't fixed width

你说的曾经没有我的故事 提交于 2019-12-08 21:03:50
I'm writing a custom View for a timer, but I can't get a properly fixed-width font for the numbers in the middle. Here's the relevant code (from two different methods): mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); mTextPaint.setTypeface(Typeface.create(Typeface.MONOSPACE, Typeface.NORMAL)); // Get rectangle that is the size of the text mTextPaint.getTextBounds( getTimeText(), 0, getTimeText().length(), mTextBounds); // X and Y coordinates of text float mTextPosX = (width / 2) - (mTextBounds.width() / 2); float mTextPosY = (height / 2) + (mTextBounds.height() / 2); // Draw text canvas

onDraw method not called in my application

北城以北 提交于 2019-12-08 20:54:42
i am developing an application, in that onDraw() is called. i am using the following logic. so, please guide where i did the mistake. MainActivity public class Hello extends Activity implements SensorListener { private MyView myView; private SensorManager sensorManager; public void onAccuracyChanged(int paramInt1, int paramInt2) { } public void onCreate(Bundle paramBundle) { super.onCreate(paramBundle); Log.e("hello", "hello"); this.myView = new MyView(this); setContentView(this.myView); this.sensorManager = ((SensorManager)getSystemService("sensor")); this.myView.setTheme(2); } protected void

Canvas OnDraw method

邮差的信 提交于 2019-12-08 11:42:21
问题 I am currently creating a maze using a pair of boolean array (horizontal and vertical) in order to draw lines for the maze. The maze only every displays 5 bools from the array at one time. Then, I have an user who is always centered and as he moves through the maze the next set of bools are drawn. This is working as it should. The issue that I am having is: when the user moves to a certain part of the maze the for loop drawing the lines becomes higher than the bool array and therefore crashes

invalidate() doesn't recall OnDraw method

时光毁灭记忆、已成空白 提交于 2019-12-08 11:33:32
问题 invalidate() doesn't recall my OnDraw() method. I use invalidate() in a setter method in the same class that OnDraw() is in. public class PuzzleDraw extends View { // defining some variables // protected void onDraw(Canvas canvas) { super.onDraw(canvas); // codes for painting puzzle // } public PuzzleDraw(Context context) { super(context); } // Method for giving cursor X/Y from MainActivity OnTouch() method and using it in OnDraw() method in some part of painting code // public void setCursor

Drawing in a Fragment in Android

我只是一个虾纸丫 提交于 2019-12-08 11:16:57
问题 I have the following code: import android.app.Fragment; import android.graphics.Rect; import android.graphics.Typeface; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.animation.AlphaAnimation; import android.widget.TextView; public class MainFragment extends Fragment { protected AlphaAnimation fadeIn = new AlphaAnimation(0.0f , 1.0f ); public MainFragment(){} public View onCreateView(LayoutInflater

Android Monospace fonts aren't fixed width

半城伤御伤魂 提交于 2019-12-08 07:28:56
问题 I'm writing a custom View for a timer, but I can't get a properly fixed-width font for the numbers in the middle. Here's the relevant code (from two different methods): mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); mTextPaint.setTypeface(Typeface.create(Typeface.MONOSPACE, Typeface.NORMAL)); // Get rectangle that is the size of the text mTextPaint.getTextBounds( getTimeText(), 0, getTimeText().length(), mTextBounds); // X and Y coordinates of text float mTextPosX = (width / 2) -

Rotatory knob moving between 150 and 210 degree

你。 提交于 2019-12-08 03:33:02
问题 I have followed the tutorial and succesfully created a Rotatory knob but it rotate full 360 degree. without stoping . I want to rotate it from 150 to 210 degrees as shown by the progress. .. How could i modify it to rotate between 150 and 210 degrees. My effort I have added given check in onDraw function protected void onDraw(Canvas c) { if(!(angle >150 && angle <210)) c.rotate(angle,getWidth()/2,getHeight()/2); super.onDraw(c); } But first time it stop it and take it back to 180 degree but

onDraw method not called in my application

╄→尐↘猪︶ㄣ 提交于 2019-12-08 03:15:17
问题 i am developing an application, in that onDraw() is called. i am using the following logic. so, please guide where i did the mistake. MainActivity public class Hello extends Activity implements SensorListener { private MyView myView; private SensorManager sensorManager; public void onAccuracyChanged(int paramInt1, int paramInt2) { } public void onCreate(Bundle paramBundle) { super.onCreate(paramBundle); Log.e("hello", "hello"); this.myView = new MyView(this); setContentView(this.myView); this

Custom drawing on top of Gallery view (and it's child views)

不问归期 提交于 2019-12-07 20:43:19
问题 I'm trying to draw custom UI (a path in this case) on top of a Gallery. I've extended the base Gallery class and overwritten the draw method like this: public class MyGallery extends Gallery { ... @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawPath(mPath, mPaint); } I thought that putting my path drawing after super.onDraw would make sure that the path was drawn on top of the gallery AND it's child views, but instead the child views are layered on top of my

How to update Android Views upon modifications?

牧云@^-^@ 提交于 2019-12-07 00:12:19
问题 I have some methods in my View that modify some of the shapes that are drawn when called. In Java in order to make sure the component is updated I would call repaint() . Is there something that will make sure my view is updated correctly? I had read somewhere that calling invalidate() in the onDraw() method would keep things up to date and therefore I wouldn't need to have something like repaint() in my methods that modify that shapes that are drawn. Is this correct, or is there something