RelativeLayout mLayout = new RelativeLayout(); //设置RelativeLayout的子控件属性对象,并设置其尺寸样式。每个GroupView中都有一个LayoutPrams,都是用来给子控件设置发生的。 RelativeLayout.LayoutPrams params = new RelativeLayout.LayoutPrams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); //增加 子控件 ImageView iv = new ImageView(getActivity()); iv.setImageResource(R.drawable.tab_icon_conversation_normal); //设置子控件在RealtiveLayout中的位置属性。 params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); //给iv 增加属性 //将iv,增加到mLayout中 mLayout .addView(iv, params);
AbsoluteLayout abslayout=new AbsoluteLayout (this); setContentView(abslayout); Button btn1 = new Button(this); btn1.setText(”this is a button”); btn1.setId(1); AbsoluteLayout.LayoutParams lp1 = new AbsoluteLayout.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0,100); abslayout.addView(btn1, lp1);
RelativeLayout relativeLayout = new RelativeLayout(this); setContentView(relativeLayout); AbsoluteLayout abslayout=new AbsoluteLayout (this); RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); lp1.addRule(RelativeLayout.ALIGN_PARENT_TOP); lp1.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE); relativeLayout.addView(abslayout ,lp1);
LinearLayout ll = new LinearLayout(this); EditText et = new EditText(); ll.addView(et); //动态添加布局的方法1. LinearLayout ll = (LinearLayout)this.getLayoutInflater().inflate(R.layout.main1,null); setContentView(ll); LinearLayout ll2 = (LinearLayout)this.getLayoutInflater().inflate(R.layout.main2,ll); //这样 main2 作为 main1的子布局 加到了 main1的 根节点下 //动态添加布局的方法2 addView. LinearLayout ll = (LinearLayout)this.getLayoutInflater().inflate(R.layout.main1,null); setContentView(ll); LinearLayout ll2 = (LinearLayout)this.getLayoutInflater().inflate(R.layout.main2,null); ll.addView(ll2);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有