Hello everyone, our tutorial is onAndroid
Custom in the tutorialView
For beginners, they are usedAndroid
The traditional page layout method is as follows:
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: Orientation = "vertical" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/> <textview <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: TEXT = "@ string/Hello" <br/> </linearlayout>
Of course, the layout method above can help us develop simple applications, but if you want to write a complex application, it will be a little far-fetched. If you don't believe it, you can study the source code, the layout of high handwriting is usually written as follows:
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <A> <br/> <B> </B> <br/> </a>
A extends linerlayout and B extends textview.
I wrote a simpleDemo
The procedure is as follows:
First createAndroid
Project name:Viewdemo
.
Then customizeView
Class, namedMyview (extends view)
The Code is as follows:
Package COM. android. tutor; <br/> Import android. content. context; <br/> Import android. graphics. canvas; <br/> Import android. graphics. color; <br/> Import android. graphics. paint; <br/> Import android. graphics. rect; <br/> Import android. graphics. paint. style; <br/> Import android. util. attributeset; <br/> Import android. view. view; <br/> public class myview extends view {<br/> private paint mpaint; <br/> private context mcontext; <br/> Private Static final string mstring = "welcome to Mr Wei's blog"; </P> <p> Public myview (context) {<br/> super (context); </P> <p >}< br/> Public myview (context, attributeset ATTR) <br/>{< br/> super (context, ATTR ); </P> <p >}< br/> @ override <br/> protected void ondraw (canvas) {<br/> // todo auto-generated method stub <br/> super. ondraw (canvas); </P> <p> mpaint = new paint (); </P> <p> // set the paint brush color <br/> mpaint. setcolor (color. red); <br/> // set filling <br/> mpaint. setstyle (style. fill); </P> <p> // draw a rectangle. The first two are the coordinates in the upper left corner of the rectangle, and the last two are the coordinates in the lower right corner. <br/> canvas. drawrect (New rect (10, 10,100,100), mpaint); </P> <p> mpaint. setcolor (color. blue); <br/> // draw text <br/> canvas. drawtext (mstring, 10,110, mpaint); <br/>}< br/>
ThenView
AddMain. xml
In the layout file, the Code is as follows:
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: Orientation = "vertical" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/> <textview <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: TEXT = "@ string/Hello" <br/> <COM. android. tutor. myview <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/> </linearlayout>
The final execution result is as follows:
OK, it's all done. I wrote it here today and started cooking. My wife and children waited for me to cook, lol ~