Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

Draw color line set stroke width Android basic example

Canvas, drawLine(), setStrokeWidth(), Paint, setAntiAlias(boolean), onDraw()

public class MainActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new SampleView(this));
	}

	private static class SampleView extends View {

		// CONSTRUCTOR
		public SampleView(Context context) {
			super(context);
			setFocusable(true);

		}

		@Override
		protected void onDraw(Canvas canvas) {

			canvas.drawColor(Color.YELLOW);
			Paint p = new Paint();
			// smooths
			p.setAntiAlias(true);
			p.setColor(Color.RED);
			p.setStrokeWidth(4.5f);
			// opacity
			p.setAlpha(0x80); //
			// drawLine (float startX, float startY, float stopX, float stopY,
			// Paint paint)
			canvas.drawLine(0, 0, 40, 40, p);
			canvas.drawLine(40, 0, 0, 40, p);

		}

	}
}

396LW NO topic_id




AD

Další témata ....(Topics)


35

Android startup tutorial for developers video | android-startup-tutorial-for-developers-video


How install Android emulator on PC
//developer.android.com/sdk/installing.html

Download links:
Java Development Kit JDK download
Eclipse download
Android SDK download