标签:风飞雪未扬 framelayout 帧布局 android布局
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <ImageView android:id="@+id/imageView1" android:layout_width="match_parent" android:layout_height="322dp" android:src="@drawable/KILL" /> <Button android:id="@+id/button1" android:layout_width="240dp" android:layout_height="107dp" android:text="Button" /> <TextView android:id="@+id/textView1" android:layout_width="154dp" android:layout_height="62dp" android:text="Large Text" android:textAppearance="?android:attr/textAppearanceLarge" /> </FrameLayout>
package com.example.framelayout; import android.os.Bundle; import android.app.Activity; import android.view.ViewGroup; import android.widget.Button; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.TextView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); FrameLayout layout = new FrameLayout(this); // 为布局设置宽度和高度 FrameLayout.LayoutParams LayoutParams = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); // 为图片设置高度和宽度 FrameLayout.LayoutParams imageLayoutParams = new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, 311); // 为按钮设置宽度和高度 FrameLayout.LayoutParams buttonLayoutParams = new FrameLayout.LayoutParams( 281, 173); // 为文字设置宽和高 FrameLayout.LayoutParams textLayoutParams = new FrameLayout.LayoutParams( 183, 85); ImageView imageView = new ImageView(this);// 创建ImageView对象 imageView.setImageResource(R.drawable.kill);// 设置图片信息 layout.addView(imageView, imageLayoutParams);// 将imageView添加到Framelayout布局当中 Button button = new Button(this);//创建Button对象 button.setText("button");//设置标题 layout.addView(button, buttonLayoutParams);//将按钮增加到Framelayout布局当中 TextView textView=new TextView(this);//创建textView对象 textView.setText("TextView");//设置标题 layout.addView(textView, textLayoutParams);//将TextView添加到Framelayout当中 super.addContentView(layout,LayoutParams);//将framelayout添加到content中 } }
从零开始学android<FrameLayout帧布局.十四.>,布布扣,bubuko.com
从零开始学android<FrameLayout帧布局.十四.>
标签:风飞雪未扬 framelayout 帧布局 android布局
原文地址:http://blog.csdn.net/u013616976/article/details/38535485