Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] android – How to constrain a View below two Views whose visibility can be switched?

Posted on November 14, 2022

Solution 1 :

As proposed by CommonsWare, it can be done with a Barrier as follows:

 <androidx.constraintlayout.widget.Barrier
          android_id="@+id/barrier"
          android_layout_width="wrap_content"
          android_layout_height="wrap_content"
          app_barrierDirection="bottom"
          app_barrierAllowsGoneWidgets="false"
          app_constraint_referenced_ids="middle1,middle2" />

Note that the IDs in app:constraint_referenced_ids are written without the @id/ prefix.

As my middle1 and middle2 have different heights and I set one of them to View.GONEI went with app:barrierAllowsGoneWidgets="false" to make sure that the Barrier position gets updated and no blank space is left over.

For more details see the official documentation or e.g. on Youtube the video ConstraintLayout Tutorial Part 4 – BARRIERS AND GROUPS – Android Studio Tutorial

Problem :

Image a ConstraintLayout which includes three vertically stacked items:

@+id/top
@+id/middle1 or @+id/middle2 (one gets View.VISIBLE, one gets View.GONE)
@+id/bottom

The top of @+id/middle1 and @+id/middle2 is constrained to the bottom of @+id/top, no issue here.

The interesting case is @+id/bottom. That shall always be placed below @+id/middle1 or @+id/middle2, depending on which one is visible (the other will get View.GONE). Is there any way to model this in the layout file or do I have to change the top constraint for @+id/bottom while switching between showing @+id/middle1 and @+id/middle2?

Comments

Comment posted by CommonsWare

Try setting up a

Comment posted by Alexander Guyer

As a generic response which works nearly universally w.r.t the layout engine, you could also just put

Comment posted by stefan.at.wpf

@CommonsWare that worked great, at least after I found out that referencing groups from barriers leads to no error message, but simple doesnt work. one needs to directly reference the single views. Can you post as answer?

Comment posted by stefan.at.wpf

@Nerdizzle Thanks, that’s what I also thought about, but this increases layout complexity and your layout won’t be flat anymore. So I am glad that at least for

READ  [ANSWERED] android - How to use google sign-in in webview apps?
Powered by Inline Related Posts

Comment posted by CommonsWare

@stefan.at.wpf: If you got it to work, I recommend that you answer your own question, since you have working code in front of you, and I do not. 🙂

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress