LinearLayout is one of the most commonly used layouts in Android, which arranges its own child elements in one direction. There are two kinds of directions, horizontal or vertical. This direction can be achieved by setting android:orientation= "vertical" or android:orientation= "horizontal", and all the elements are arranged one after the other. If it is arranged vertically, then the elements of the linearlayout are arranged vertically from top to bottom, for example, in the following example, the view of Mainactivity is arranged in such a vertical way. If it is arranged horizontally, then the child elements inside the linearlayout are arranged from left to right.
Example: Layoutdemo
Operating effect:
Code Listing:
Layout file: Main.xml
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:orientation=" vertical " android:layout_width=" fill_parent " android:layout_height=" Fill_parent " > <button android:id=" @+id/button1 " android:layout_width=" Fill_parent " android:layout_height= "Wrap_content" android:text= "relativelayout use" /> <button Android:id= "@+id/button2" android:layout_width= "fill_parent" android:layout_height= "Wrap_content" android:text= "framelayout use" /> <button android:id= "@+id/button3" android: Layout_width= "Fill_parent" android:layout_height= "wrap_content" android:text= "tablelayout use" / ></LinearLayout>
Java source code file: Mainactivity.java
Package Com.rainsong.layoutdemo;import Android.app.activity;import Android.os.bundle;public class MainActivity Extends activity{ /** called when the Activity is first created. * /@Override public void OnCreate (Bundle save Dinstancestate) { super.oncreate (savedinstancestate); Setcontentview (R.layout.main); }}
LinearLayout of the Android UI layout