当前位置:网站首页>Dynamically add and delete layouts
Dynamically add and delete layouts
2022-04-23 18:41:00 【Xiao Xiaofeng】
Main code :
/** * Add and remove people * @param str */
private void add(String str) {
ll = (LinearLayout) findViewById(R.id.line_);
params = new LinearLayout.LayoutParams(AutoLinearLayout.LayoutParams.MATCH_PARENT, 120);
View l = LayoutInflater.from(this).inflate(R.layout.item_, null);
params.setMargins(20, 20, 20, 20);//4 The two parameters are to set the upper left and lower right margins in order
if (l.getParent() != null)
((ViewGroup) l.getParent()).removeView(l);
ll.addView(l, params);
TextView tv = l.findViewById(R.id.tv_);
tv.setText(str);
l.findViewById(R.id.img_).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ll.removeView((View) view.getParent());// Remove the currently clicked add item
}
});
}
版权声明
本文为[Xiao Xiaofeng]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210604091508.html
边栏推荐
猜你喜欢
Kettle paoding jieniu Chapter 17 text file output
Iptables - L executes slowly
ctfshow-web362(SSTI)
Use stm32cube MX / stm32cube ide to generate FatFs code and operate SPI flash
Imx6 debugging LVDS screen technical notes
With the use of qchart, the final UI interface can be realized. The control of qweight can be added and promoted to a user-defined class. Only the class needs to be promoted to realize the coordinate
【数学建模】—— 层次分析法(AHP)
ESP32 LVGL8. 1 - textarea text area (textarea 26)
kettle庖丁解牛第17篇之文本文件输出
In win10 system, all programs run as administrator by default
随机推荐
Excel intercept text
Daily CISSP certification common mistakes (April 12, 2022)
Ionic 从创建到打包指令集顺序
CISSP certified daily knowledge points (April 19, 2022)
Daily CISSP certification common mistakes (April 11, 2022)
深入理解 Golang 中的 new 和 make 是什么, 差异在哪?
【科普】CRC校验(一)什么是CRC校验?
ESP32 LVGL8. 1 - img picture (IMG 20)
Notepad + + replaces tabs with spaces
Go 语言 GUI 框架 fyne 中文乱码或者不显示的问题
How can programmers quickly develop high-quality code?
Sentinel rule persistence into Nacos
K210串口通信
Nacos作为服务配置中心实战
机器学习理论之(8):模型集成 Ensemble Learning
CISSP certified daily knowledge points (April 13, 2022)
CISSP certified daily knowledge points (April 11, 2022)
Resolution: cnpm: unable to load file \cnpm. PS1, because running scripts is prohibited on this system
【数学建模】—— 层次分析法(AHP)
Interpretation and compilation of JVM