Search code examples
androidkotlinandroid-constraintlayout

How to make scrollView not jump up when textview is removed? (Kotlin)


I have a scrollView that is constrained to a TextView above it. I also have a button next to that TextView that when pressed makes that Textview invisible. However when I press the button, the code works perfectly, but the scrollview overlaps the button and its own texts. Is there a way I could "double constrain" it to the button when the textview is not there? Or any other ways I would be able to do it? Thanks.


Solution

  • There are a lot of ways to not fall into this issue like if you use visibility = Invisible instead of Gone:

    textView.visibility = View.INVISIBLE
    

    Or You can just put the TextView and the Button in a CardView then constriant the CardView with the ScrollView (which will be outside of the CardView).