package com.develop.common.ui

import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.view.ViewGroup
import android.view.ViewTreeObserver
import android.widget.LinearLayout
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.children

class AdaptLinearLayout(context: Context, attrs: AttributeSet) : LinearLayout(context, attrs) {

    init {

       viewTreeObserver.addOnGlobalLayoutListener {
           if (childCount > 0) {
               val lastChild =  children.last { it.visibility == View.VISIBLE }
               if (lastChild.visibility == View.VISIBLE) { // 检查最后一个子视图是否可见
                   val layoutParams =
                       lastChild.layoutParams as LinearLayout.LayoutParams // 获取最后一个子视图的布局参数
                   layoutParams.marginEnd = 0 // 设置最后一个子视图的rightMargin属性为0
                   lastChild.layoutParams = layoutParams // 将更新后的布局参数应用到最后一个子视图中
               }
           }
       }

    }




}