布局方法分類:
執行個體:
1.實現Linear布局
代碼清單:
1. MainActivity.java
package com.jk.test;import android.os.Bundle;import android.app.Activity;import android.view.Menu;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.first_layout);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}
2.first_layout.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#ff0000" android:text="first"/><TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#00ff00" android:text="second"/></LinearLayout>
2.first_layout.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#ff0000" android:text="first"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#00ff00" android:text="second"/></LinearLayout>
相應的使用不同的布局需要修改你的xml檔案即可。