Linear Layout
Linear Layout place the controls in one line either horizontal or vertical. The direction will be specified by android:orientation attribute.
For Example :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"> <Button android:id="@+id/welcomebutton" android:text="Welcome" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:text="CreativeAndroidApps" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>
see the below screen shot
Linear Layout |
See here how to create the LinearLayout in code
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout ll;
ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.HORIZONTAL);
TextView tv = new TextView(this);
tv.setText(" CreativeAndroidApps");
Button bv = new Button(this);
bv.setText("Welcome");
ll.addView(tv);
ll.addView(bv);
}
to change the orientation to vertical use LinearLayout.VERTICAL in setOrientation
method
The forms are normally created using linear layouts.
No comments:
Post a Comment