代码控制控件的layout_weight属性和结合xml填充屏幕

//效果图:


//代码

protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		
		Button button1=(Button)this.findViewById(R.id.button);
		Button button2=(Button)this.findViewById(R.id.button2);
		//layout:设计、params:参数
		button1.setLayoutParams(new LinearLayout
				.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.FILL_PARENT,1));
		button2.setLayoutParams(new LinearLayout
				.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,2));		
		
	}

//demo2

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.layoutdemo.MainActivity$PlaceholderFragment" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="45dip"
        android:background="@drawable/a"
        android:gravity="center"
        android:text="设 置" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0.0dp"
        android:layout_weight="1.0" >

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:scaleType="fitXY"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="45dip"
        android:background="@drawable/a"
        android:drawableLeft="@drawable/ic_launcher"
        android:gravity="center_vertical"
        android:text="小机器人" />

</LinearLayout>

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念