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

2018-04-07 15:22:25

引用第三方layout中的布局

  1. LinearLayout rightContentView = (LinearLayout) findViewById(R.id.lyt_chat_content);  

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

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

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

  5. 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();


  • 2020-05-07 13:05:28

    JavaScript中批量设置Css样式

    setAttribute() 方法添加指定的属性,并为其赋指定的值。 如果这个指定的属性已存在,则仅设置/更改值

  • 2020-05-07 13:07:21

    scrollBox 跑马灯滚动js

    ​这个插件可以很好的实现跑马灯,以及轮播图等效果,scrollBox js

  • 2020-05-07 13:21:25

    JS中获取 DOM 元素的绝对位置实例详解

    在操作页面滚动和动画时经常会获取 DOM 元素的绝对位置,例如 本文 左侧的悬浮导航,当页面滚动到它以前会正常地渲染到文档流中,当页面滚动超过了它的位置,就会始终悬浮在左侧。

  • 2020-05-07 13:42:13

    场景切换的集合移动,旋转,淡入淡出等

    两个场景(即两个div视图)切换的时候,如果想添加个过渡动画,除了可以使用js来实现,还可以通过CSS3的animation属性来实现。 (注意:Internet Explorer 9 以及更早的版本不支持 animation 属性。)