Custom Views in Android
Filed under: Android Author: Shahab HameedCustom Views
Built-in widgets/components/views in Android include
Button
TextView
EditText
ListView
CheckBox
RadioButton
Gallery
Spinner
AutoCompleteTextView
Image Switcher
Text Switcher
→ If the built-in views don't meet your requirements, you can create your own View subclass. There are two ways of doing this.
1) For small adjustments to an existing built-in-view simply subclass the built-in-view and override its methods
2) You can create your own View subclass
→ If you choose to create your own View subclass, you can following advantages
a) You get control over the appearance and function of a screen element (custom view)
b) You can create a volume control knob-type custom view using Android 2D graphics.
c) You can combine 2-3 different built-in-controls and make a compound complex custom view.
There is an example in the Android Demo API's (Notepad Tutorial). The example overrides EditText Button to create Notepad lined page effect.
d) You can capture key presses and handle them in some custom way.
High Level-Basic Approach (If you are extending a Built-in View)
1) Extend an existing View (Built-in View). Sublass it with your own class
2) Override methods from the superclass that start with “on”.
a) onDraw()
b) onMeasure()
c) onKeyDown() , onKeyUp(), onTouch() … and so on
3. Use your new Views in your Activity
→ setContentView (View v)
→ < view class = viewclass >
→ < view class = < parentclass > $ < viewclass > >
For fully customized View1) You have to extend View class.
2) Implement constructor myView(attributes, parameters)
3) Implement event listeners
4) Override methods from the superclass that start with “on”.
a) onDraw()
b) onMeasure()
5) Use your new Views in your Activity
→ setContentView (View v)
→ < view class = viewclass >
→ < view class = < parentclass > $ < viewclass > >
P.S. Sample Code (Eclipse Project) can be downloaded from here.
ixgames
August 23, 2011 at 8:14 PM
Recently I downloaded new version of the corona, but apparently the only apk's processor runs on mobile phones ARMv7 .. but my processor and ARMv6 .. and I do not make much sense to buy something that I can not even test on my phone. then researches his topic and found a site where a talking version of the sdk corona 450. that ran in ARMv6 ..
have any source where I can download this version. advises me or something else?
I intend to do some games with 2D and 2.5D games ..
with best regards Jorge Sousa
morenito-green-eyes@hotmail.com
sorry for my english ...
Shahab Hameed
September 9, 2011 at 4:22 PM
I completely understand what you mean. Yes if your Android phone has a ARMv6 processor you'll need Corona SDK 450 .
You can download it from http://developer.anscamobile.com/sites/default/files/CoronaSDK_2011.450.msi
Good luck with game development.