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-12-07 22:06:13

    System Extension Blocked - warning

    After upgrading your macOS computer to High Sierra 10.13.4 or higher (starting in April 2018), you may see a message about a System Extension Blocked. At Williams we have seen this warning appear for these programs:

  • 2020-12-08 08:57:12

    win10上使用win-sshfs

    首先在GitHub上下载DokanSetup-1.0.5.1000和WinSSHFS-1.6.1.13-devel 注意:Dokan不能使用最新的版本,得使用1.0.5版本。要不win-sshfs会报Dokan版本错误的问题。(win10版本)

  • 2020-12-08 11:51:54

    Ubuntu安装Node.js和npm

    Node.js是基于Chrome的JavaScript构建的跨平台JavaScript运行时环境,npm是Node.js的默认程序包管理器,也是世界上最大的软件注册表。本篇文章展示了三种在Ubuntu 20.04服务器上安装Node.js和npm的方法。

  • 2020-12-08 17:13:57

    nvm卸载、安装node和npm

    1、node.js、nvm、 npm (1)在cmd中输入`where node`找到node长须所在位置进行删除 (2)确保计算机-环境变量删除相关引用 (3)在cmd中输入`node -v` ,得到以下结果,删除成功

  • 2020-12-08 17:23:36

    Window下完全卸载删除Nodejs

    1.从卸载程序卸载程序和功能。 2.重新启动(或者您可能会从任务管理器中杀死所有与节点相关的进程)。 3.寻找这些文件夹并删除它们(及其内容)(如果还有)。根据您安装的版本,UAC设置和CPU架构,这些可能或可能不存在: