android:gravity
|
setGravity(int)
|
设置对齐方式,该属性支持:top、bottom、left、right、center_vertical、fill_vertical、center_horizontal、fillhorizontal、center、fill、clip_vertical、clip_horizontal几个属性值,当设置多个值同时生效时,用竖线“|”分隔(两边不能有空格)
|
android:orientation
|
setOrientation(int)
|
设置组件的排列方式,该属性支持:horizontal(水平)、vertical(垂直)。
|
main.xml:
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/root"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical" >
- <TextView
- android:id="@+id/show"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:background="#00ff00"
- android:text="@string/hello" />
- <Button
- android:id="@+id/ok"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="测试的安卓按钮" />
- </LinearLayout>
java文件:
- import java.util.Date;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- public class AndroidtestActivity01 extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);//选择布局文件
- Button bn=(Button) findViewById(R.id.ok);
- bn.setOnClickListener(
- new View.OnClickListener(){
- public void onClick(View v){
- final TextView show=(TextView)findViewById(R.id.show);
- show.setText("hello!安卓:"+new Date());
- }
- }
- );
- }
- }