分类: 系统运维
2012-02-08 16:43:45
main.xml
xmlns:android="
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
android:src="@drawable/fish"
android:layout_width = "wrap_content"
android:layout_height= "wrap_content"/>
android:text="请输入姓名"
android:layout_width = "wrap_content"/>
android:id="@+id/mybut"
android:layout_width = "wrap_content"
android:layout_height= "wrap_content"
android:text="按我" />
通过activity定义framelayout(与main.xml无关)
package your.packfage.namespace;
import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
public class FrameLayoutActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
FrameLayout layout = new FrameLayout(this);//定义帧布局管理器
FrameLayout.LayoutParams layoutParam= new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.FILL_PARENT) ;//定义布局管理器参数
FrameLayout.LayoutParams viewParam= new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT) ;//定义显示组件参数
ImageView img = new ImageView(this) ;//定义图片组件
img.setImageResource(R.drawable.fish);
EditText edit = new EditText(this) ;
edit.setText("请输入姓名") ;
Button but = new Button(this) ;
but.setText("按我");
layout.addView(img,viewParam);
layout.addView(edit,viewParam);
layout.addView(but,viewParam);
super.setContentView(layout,layoutParam) ;//向屏幕上增加布局管理器
setContentView(R.layout.main);
}
}