android - 当 LinearLayout 移动到另一个地方时,按钮丢失 onClickListener
问题描述
所以,我正在Android Studio中制作一个应用程序,遵循一些表格的命令。有一部分我必须开发动态 UI,所以我必须更改应用程序以创建灵活的横向布局。横向模式下的正常应用程序有 2 个垂直的主要 LinearLayout,每个权重为 0.5。
基本上,目标是检查左侧 LinearLayout “父亲”在横向模式下是否有足够的高度,以便在里面放置 3 个 LinearLayout “孩子”。如果没有,我必须将最后一个 LinearLayout 孩子传递给另一半 LinearLayout “父亲”。
我为此开发了这段代码:
val topLayout = findViewById<LinearLayout>(R.id.layoutTop)
val heightNeeded :Int = findViewById<LinearLayout>(R.id.linearLayoutRed).height * 3
if ( topLayout.height < heightNeeded ) {
val blueLayout = findViewById<LinearLayout>(R.id.linearLayoutBlue)
val secondHalf = findViewById<LinearLayout>(R.id.linearLayoutSecondHalf)
val totalValueL = findViewById<LinearLayout>(R.id.linearLayoutResultingColor)
topLayout.removeView(blueLayout)
if (blueLayout.parent != null) {
(blueLayout.parent as ViewGroup).removeView(blueLayout)
}
secondHalf.removeView(totalValueL)
if (totalValueL.parent != null) {
(totalValueL.parent as ViewGroup).removeView(totalValueL)
}
val paddTop = blueLayout.paddingTop
blueLayout.setPaddingRelative(0,paddTop,0,0)
secondHalf.addView(blueLayout)
secondHalf.addView(totalValueL)
它工作并完成了我想要的结果,但是我移动到另一个 LinearLayout 的 LinearLayout 中的所有内容都失去了它们的活动。例如,在里面我有 2 个按钮正在调用一个函数,现在我无法点击它们,它无法识别它们。
请你帮助我好吗?谢谢
解决方案
推荐阅读
- python - 安装书签失败:“找不到与书签匹配的发行版”
- node.js - 寻找对我提出的架构的一些验证(或完全彻底的破坏)
- powershell - 在powershell中使用for循环创建自定义对象类型
- amazon-web-services - 每天在哪里拍摄 AWS 弹性搜索快照?
- javascript - 如何检测javascript中的prefers-color-scheme变化?
- c# - c#反序列化异常InvalidOperationException:
没想到。如何从 XML 导入数组 - logstash - 使用 .conf 文件 logstash 获取日志文件中的时间戳
- c++ - 如何制作 GL_LINE_LOOP 抗锯齿?
- javascript - Bootstrap CSS/Javascript 仅用于轮播
- r - 评估多个选项之间一点的最近距离?