day2-layout1

layout程序说明:


在主页面Activity:
设置了Button,OnClickListener(onClick方法);
给Button设置单击监听器
在每个Button的单击监听中,跳转到另一个activity

 
LinearLayout标签:将自己的子元素按照一个方向排列(从上到下,从左到右)
         android:orientation="vertical"   "horizontal"
FrameLayout标签:预定好的空白区域,可以往里填充元素。但是所有元素都会放在其左上区域,会重叠显示
       android:layout_width="wrap_content" //fill_parent
       android:layout_height="wrap_content"   //fill_parent
       android:id="@+id/photo"   //id用于在程序中使用。findViewById(R.id.photo)
       android:src="@drawable/bg" 
RelativeLayout标签:子元素是相对于子元素相对布局的
             android:background="@drawable/blue" //@drawable/blue是#770000ff
        android:padding="10dip"   //依赖于设备的像素。 padding:填充;margin:边距
        android:layout_below="@id/label"  //经典的相对布局
        android:layout_alignParentRight="true" //和父容器的右边齐平
        android:layout_marginLeft="10dip"  //左边距为10dip
        android:layout_toLeftOf="@id/cancel" //在XXX左边
        android:layout_alignTop="@id/cancel" //和xxx高度齐平

复杂应用:在程序里将两个RelativeLayout组成一个LinearLayout,然后把这个Layout赋给Activity。
          (1)获取RelativeLayout
             LayoutInflater:对xml布局文件解析,生成RelativeLayout
           LayoutInflater inflate = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  RelativeLayout layoutLeft = (RelativeLayout) inflate.inflate(R.layout.left, null);
  RelativeLayout layoutRight = (RelativeLayout) inflate.inflate(R.layout.right, null);
   (2)RelativeLayout.LayoutParams 关于layout的长,宽等信息
  RelativeLayout.LayoutParams relParam = new RelativeLayout.LayoutParams       

(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);

TableLayout标签:表格布局
TableRow标签:定义了表格布局里的一行。每一行里面都可以自由加入一些组件

 OnClickListener listerner0=null;
 Button button0;
 public void onCreate(Bundle savedInstanceState){
  super.onCreate(savedInstanceState);
  listerner0=new OnClickListener(){
   public void onClick(){
    Intent intent0=new Intent(ActivityMain.this,ActivityFrameLayout.class);
    setTitle("XXX");
    startActivity();
   }
  };
  setContextView(R.layout.main);
  button0=(Button)findViewByid(R.id.button0);
  button0.setOnClickListener(listerner0);
 }

 //复杂应用
    public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  LinearLayout layoutMain = new LinearLayout(this);
  layoutMain.setOrientation(LinearLayout.HORIZONTAL);
  setContentView(layoutMain);
  LayoutInflater inflate = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  RelativeLayout layoutLeft = (RelativeLayout) inflate.inflate(
    R.layout.left, null);
  RelativeLayout layoutRight = (RelativeLayout) inflate.inflate(
    R.layout.right, null);

  RelativeLayout.LayoutParams relParam = new RelativeLayout.LayoutParams(
    RelativeLayout.LayoutParams.WRAP_CONTENT,
    RelativeLayout.LayoutParams.WRAP_CONTENT);
  layoutMain.addView(layoutLeft, 100, 100);
  layoutMain.addView(layoutRight, relParam);
 }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值