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

前端之家收集整理的这篇文章主要介绍了代码控制控件的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>

原文链接:https://www.f2er.com/xml/298914.html

猜你在找的XML相关文章