mainActivity如下:
- package
com.c; -
- import
android.os.Bundle; - import
android.app.Activity; -
- public
class MainActivity extends Activity { -
-
@Override -
protected void onCreate(Bundle savedInstanceState) { -
super.onCreate(savedInstanceState); -
} -
public void testHorizontal(){ - //
- //
xmlns:android="http://schemas.android.com/apk/res/android" - //
android:layout_width="match_parent" - //
android:layout_height="match_parent" - //
android:orientation="horizontal" - //
> - //
- //
- //
android:layout_width="wrap_content" - //
android:layout_height="wrap_content" - //
android:layout_marginLeft="20dip" - //
android:layout_marginRight="10dip" - //
android:text="button1" /> - //
- //
android:layout_width="wrap_content" - //
android:layout_height="wrap_content" - //
android:layout_marginLeft="20dip" - //
android:layout_marginRight="20dip" - //
android:text="button2" /> - //
- //
android:layout_width="wrap_content" - //
android:layout_height="wrap_content" - //
android:layout_marginLeft="20dip" - //
android:layout_marginRight="10dip" - //
android:text="button3" /> - //
- //
-
-
-
} -
- }
**
horizontal.xml如下:
- <</span>LinearLayout
-
xmlns:android="http://schemas.android.com/apk/res/android" -
android:layout_width="match_parent" -
android:layout_height="match_parent" -
android:orientation="horizontal" -
> -
<</span>Button -
android:layout_width="wrap_content" -
android:layout_height="wrap_content" -
android:layout_marginLeft="20dip" -
android:layout_marginRight="10dip" -
android:text="button1" /> -
<</span>Button -
android:layout_width="wrap_content" -
android:layout_height="wrap_content" -
android:layout_marginLeft="10dip" -
android:layout_marginRight="20dip" -
android:text="button2" /> -
<</span>Button -
android:layout_width="wrap_content" -
android:layout_height="wrap_content" -
android:layout_marginLeft="10dip" -
android:layout_marginRight="10dip" -
android:text="button3" /> -
- </</span>LinearLayout>
vertical.xml如下:
- <</span>LinearLayout
-
xmlns:android="http://schemas.android.com/apk/res/android" -
android:layout_width="match_parent" -
android:layout_height="match_parent" -
android:orientation="vertical" -
> -
-
<</span>Button -
android:layout_width="wrap_content" -
android:layout_height="wrap_content" -
android:layout_marginTop="30dip" -
android:layout_marginBottom="130dip" -
android:text="button1" /> -
<</span>Button -
android:layout_width="wrap_content" -
android:layout_height="wrap_content" -
android:layout_marginTop="60dip" -
android:text="button2" /> -
<</span>Button -
android:layout_width="wrap_content" -
android:layout_height="wrap_content" -
android:layout_marginTop="40dip" -
android:layout_marginBottom="10dip" -
android:text="button3" /> -
-
- </</span>LinearLayout>