I\'m using ConstraintLayout where I will show as below
I would like to hide First
(using gone), and which the view I expect to be as below (whe
Say, you want to have a picture like this:
Here you have indents between the title and "Nice work", between "Nice work" and time, also horizontal indent to "Opinions". They are centered vertically.
"Opinions" is attached to the star, so that can be multilined and stay centered. I show results for 2 variants: in the first row opinions are multilined, while in the next row it is a single line. In columns you can see 4 variants of showing/hiding 2 labels.
A more simple and preferrable way is to wrap both labels into LinearLayout
and insert it into parent ConstraintLayout
. Then you can set vertical gravity, show or hide labels, hide the LinearLayout
itself.
If you don't want to have nested layouts, use Barrier
s and Group
s. It is a difficult task that can waste many hours. A key is having additional View
s for aligning. Here I have 2 hiding labels ("Nice work" and "Opinions"), and I have to add 2 views (spaces).
The height of the right space is equal to the height of the star (14dp).
To simplify hiding several views, I joined them into groups.
You can see horizontal dotted lines - they are Barrier
s. I align them on tops and bottoms of the most big views (barrier_2 is similar):
Vertical aligning is based on these 2 additional Space
s (see marginTop="10dp"):
It is difficult to cover all situations, so see the following layout:
Then in your activity you can show/hide labels. Hide Group
s, not views inside, because strangely inside a Group
views are always visible.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)
left_text_group.visibility = View.GONE
opinion_group.visibility = View.VISIBLE
}