Android 将LinearLayout移动到其他位置时,单击Listener时按钮丢失

Android 将LinearLayout移动到其他位置时,单击Listener时按钮丢失,android,android-studio,kotlin,Android,Android Studio,Kotlin,所以,我正在Android Studio中制作一个应用程序,遵循一些表单的顺序。有一部分我必须开发一个动态UI,所以我必须改变de应用程序,以创建一个灵活的横向布局。 横向模式下的正常应用有两个垂直的主线布局,每个权重为0.5 基本上,目标是检查左侧线性布局“父亲”在横向模式下是否有足够的高度,以使3线性布局“孩子”在内部。如果不是,我必须把最后一个线性布局的孩子传给另一半线性布局的“父亲” 为此,我开发了以下代码: val topLayout = findViewById<LinearL

所以,我正在Android Studio中制作一个应用程序,遵循一些表单的顺序。有一部分我必须开发一个动态UI,所以我必须改变de应用程序,以创建一个灵活的横向布局。 横向模式下的正常应用有两个垂直的主线布局,每个权重为0.5

基本上,目标是检查左侧线性布局“父亲”在横向模式下是否有足够的高度,以使3线性布局“孩子”在内部。如果不是,我必须把最后一个线性布局的孩子传给另一半线性布局的“父亲”

为此,我开发了以下代码:

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)
val topLayout=findViewById(R.id.layoutTop)
val heightNeeded:Int=findViewById(R.id.linearLayoutRed)。高度*3
如果(顶部布局高度<所需高度){
val blueLayout=findViewById(R.id.linearLayoutBlue)
val secondHalf=findViewById(R.id.linearLayoutSecondHalf)
val totalValueL=findViewById(R.id.linearLayoutResultingColor)
topLayout.removeView(蓝色布局)
if(blueLayout.parent!=null){
(blueLayout.parent作为视图组)。移除视图(blueLayout)
}
第二部分。移除视图(totalValueL)
if(totalValueL.parent!=null){
(totalValueL.parent作为视图组)。移除视图(totalValueL)
}
val paddTop=blueLayout.paddingTop
blueLayout.setPaddingRelative(0,paddTop,0,0)
secondHalf.addView(blueLayout)
secondHalf.addView(totalValueL)
它起作用了,达到了我想要的效果,但我移动到另一个LinearLayout的LinearLayout中的所有内容都失去了它们的活动。例如,在LinearLayout中,我有两个按钮在调用函数,现在我无法单击它们,它无法识别它们

你能帮帮我吗?
谢谢

你能发布你的XML布局代码吗?它有点太长了,你想让我如何发送它?只需编辑你的问题,在底部添加它。不管怎样,找到它,这不是我的错误,是我调用它的方式。无论如何,谢谢