android如何引用布局,android 动态布局与引用第三方layout中的布局

引用第三方layout中的布局LinearLayout rightContentView = (LinearLayout) findViewById(R.id.lyt_chat_content);

View child =  LayoutInflater.from(this).inflate(R.layout.qa_text,null);// 由Layout的Id获得对应的View

rightContentView .removeAllViews(); // 清除View里面的所有View

LayoutParams layoutParams = newLayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);

rightContentView.addView(child, layoutParams);

这段代码实现了将rightContentView里面的子View全部清空,然后替换成 qa_text 这个Layout 布局。

这段代码用于实现Layout里面子layout的动态切换。

android 动态布局

一个在LinearLayout下的控件生成方法

(若是在RelationLayout下将LinearLayout.LayoutParams改为RelationLayout.LayoutParams)/**

* 创建一个textView,参数为文本框内容

*/

private void creatText(String str) {

TextView textView = new TextView(this);

textView.setPadding(10, 10, 10, 10);

textView.setText(str);

params=new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);

params.setMargins(30, 10, 30, 0);

layout.addView(textView,params);

}

/**

* 创建一个iamgeview,参数为图片名 R.drawable.image

*/

private void imageView(int drawable){

ImageView image = new ImageView(this);

image.setImageResource(drawable);

params=new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,600);

params.setMargins(30, 20, 30, 20);

layout.addView(image,params);

}

第三方扩展,获得父级布局元素FrameLayout view = (FrameLayout  )getWindow().getDecorView();

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值