0

I'm trying to make visibility changes for a view under MotionLayout using this answer https://stackoverflow.com/a/62658424/5412554 but for me, it's not working under observe. For eg:

viewModel.messageLinkedList.observe(viewLifecycleOwner) {
binding.motionLayout.getConstraintSet(R.id.start).getConstraint(binding.deleteAllText.id).propertySet.mVisibilityMode = 1; // 1 - ignore or 0 - normal
binding.deleteAllText.visibility = View.GONE
}

If I use simply in onCreateView of fragment it works.

For eg:

binding.motionLayout.getConstraintSet(R.id.start).getConstraint(binding.deleteAllText.id).propertySet.mVisibilityMode = 1; // 1 - ignore or 0 - normal
binding.deleteAllText.visibility = View.GONE

Please help me with the correct solution.

1 Answers1

0

I don't know it works with data-binding but I found a Solution for Kotlin, maybe you can something figure out:

motion_layout_id.getConstraintSet(R.id.start)?.let {
            it.setVisibility(R.id.deleteAllText, View.GONE)
            motion_layout_main.requestLayout() // this must be done to apply the visibility change
        }
Andrey
  • 55
  • 7