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


  • 2021-01-22 22:01:19

    Emscripten Compiler Frontend (emcc)

    The Emscripten Compiler Frontend (emcc) is used to call the Emscripten compiler from the command line. It is effectively a drop-in replacement for a standard compiler like gcc or clang.

  • 2021-01-22 22:21:41

    emcc编译命令介绍

    这个输入文件file,既可以是clang可以编译的C/C++语言,也可以是二进制形式的llvm bitcode或者人类可读形式的llvm assembly文件。

  • 2021-01-22 22:25:51

    How to protect your JS code by WebAssembly

    对于iOS或是Android来说,我们可以将相关的算法通过C/C++进行编写,然后编译为dylib或是so并进行混淆以此来增加破解的复杂度,但是对于前端来说,并没有类似的技术可以使用。当然,自从asm.js及WebAssembly的全面推进后,我们可以使用其进一步增强我们核心代码的安全性,但由于asm.js以及WebAssembly标准的开放,其安全强度也并非想象中的那么美好。

  • 2021-01-24 09:50:16

    UICollectionViewCell cell高度自适应

    本来想使用UICollectionView来作为整体的布局,并且不再使用UITableView,但是发现高度不固定的布局,UICollectionView没啥优势呀,至少我没找到好的方法,从网上看的是,要自定义cell,并且继承preferredLayoutAttributesFittingAttributes