Tutorial by Examples

If you need a completely customized view, you'll need to subclass View (the superclass of all Android views) and provide your custom sizing (onMeasure(...)) and drawing (onDraw(...)) methods: Create your custom view skeleton: this is basically the same for every custom view. Here we create the...
Custom views can also take custom attributes which can be used in Android layout resource files. To add attributes to your custom view you need to do the following: Define the name and type of your attributes: this is done inside res/values/attrs.xml (create it if necessary). The following file...
A compound view is a custom ViewGroup that's treated as a single view by the surrounding program code. Such a ViewGroup can be really useful in DDD-like design, because it can correspond to an aggregate, in this example, a Contact. It can be reused everywhere that contact is displayed. This means t...
Do not allocate new objects in onDraw @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Paint paint = new Paint(); //Do not allocate here } Instead of drawing drawables in canvas... drawable.setBounds(boundsRect); drawable.draw(canvas); Use a B...
Main motive to develop this compound view is, below 5.0 devices does not support svg in drawable inside TextView/EditText. One more pros is, we can set height and width of drawableRight inside EditText. I have separated it from my project and created in separate module. Module Name : custom_edit_d...
Many custom views need to accept user interaction in the form of touch events. You can get access to touch events by overriding onTouchEvent. There are a number of actions you can filter out. The main ones are ACTION_DOWN: This is triggered once when your finger first touches the view. ACTION_MO...

Page 1 of 1