Thursday, 27 August 2015

Create your own layout using Java

Add a Large text from widgets in Design view of xml file. Let it be anywhere.
It will look like the figure
Now run the emulator. Its output will be as shown in figure.

Now go to MainActivity.java file.

Try to analyze the onCreate method. Here setContentView function displays the layout on the screen. Comment the like
And again run the app on emulator.
The output will not show the text because it was the part of that layout.
Now. Write the two lines on code in onCreate method.
Here we create a new object of class RelativeLayout named as MyLayout and then we display the layout on screen. If we run the application now then it won’t show that text because it was the part of RelativeLayout and now of MyLayout.
In future tutorials when we will add texts and buttons to MyLaout, you will better understand this concept.


No comments:

Post a Comment