Development issue/problem:

I am using ConstraintLayout, which is shown below.

I want to hide First (with away), and have the view I’m waiting for below (where ElasticBody stretches to use First’s original view as well.

However, when I installed First to go, my view looked just like the one below (all images as in the Android Studio Design view). My elastic body is also absent, and growth has increased strangely.

My formatting code as shown below

(Note that if you delete the missing person, you get the first image).
Why? How do I fix it if my first one was gone, can I stretch the elastic body properly?

P/s : I know how to do it linearly and relatively…. but I’m wondering if it’s a constraint on ConstraintLayout?

How can I solve this problem?

Solution 1:

Try to follow him.

Set the first view on the left and the upper limits of the parent view. After that:

  • txt_body text display width to 0dp.
  • place the left edge on the right side of the first view
  • put the right restriction on the left side of the rear view.

In this way, the view of the body is stretched as you wish if you leave out the first view.

Update

If you want to work with a fence, you can do that too.

Solution 2:

You can also use Visibility.GONE in ConstraintLayout : Obstacles.

If you are not familiar with the Obstacles section, please inquire: Obstacles

Solution 3:

Tell me you want a picture like this:

ConstraintLayout, when constraint dependent view is gone, the layout view behave weirdly –

There is a dash between the title and Good Work, between Good Work and Time, and a horizontal dash for Opinions. They are arranged vertically.

ConstraintLayout, when constraint dependent view is gone, the layout view behave weirdly –

Minds are attached to the star so they can stay in the middle. I show the results for 2 options: the first reporting line is multilinear, the next line is a single line. In the columns you will see 4 options to view/open 2 labels.

ConstraintLayout, when constraint dependent view is gone, the layout view behave weirdly –

  1. A simpler and more efficient method is to wrap both labels in the LinearLayout and place them in the parent ConstraintLayout. You can then adjust the vertical gravity, show or hide the labels, and hide the LinearLayout itself.
  2. If you don’t want to have plans, use barriers and groups. This is a difficult task that can take many hours. The button has additional views for alignment. Here I have 2 hidden tags (Good work and Opinions) and need to add 2 views (spaces).

ConstraintLayout, when constraint dependent view is gone, the layout view behave weirdly –

The height of the desired room is equal to the height of the star (14dp).

To make it easier to hide certain views, I’ve grouped them together.

ConstraintLayout, when constraint dependent view is gone, the layout view behave weirdly –

You can see that the dotted horizontal lines are the barriers. I align them with the ups and downs of the larger views (Barrier_2 is similar) :

ConstraintLayout, when constraint dependent view is gone, the layout view behave weirdly –

The vertical alignment is based on these 2 extra spaces (see marginTop=10dp) :

It is difficult to cover all situations, so see the chart below:

You can then show/hide labels in your activity. Hide the groups, not the view inside, because oddly enough the groups are always visible inside the view.

fun override onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)

left_textgroup.visibility = View.GONE
opinion_group.visibility = View.VISIBLE
}.

Solution 4:

The answer has already been given regarding the obstacles. I’ll give you an example of how I implemented it:

This example shows 2 TextViews, each of which can disappear. The views are stacked from top to bottom, so that the Directional Barrier is placed at the bottom. If you need a different direction, just change this line.

If we set one of the two TextViews to away, the barrier is moved down, and if we set both to away, it is simply moved to the element referenced by the top TextView1 constraint, in this case the parent.

Pay attention: If the top constraint of your textView1 is something else, i.e. it is under another element, then the barrier will be there when the two views are apart.

Good luck!

 constraint layout vertical weightconstraint layout weight sumapp:layout_constrainthorizontal_weightconstraintlayout barrierconstraint layout conditionallayout_constraintvertical_weight not workingconstraint layout vs relative layoutconstraintlayout versionconstraint layout overlappingconstraintlayout flowandroid-constraintlayout programmaticallyconstraint layout not showing properlyconstraint layout hide multiple viewsbarrier in constraintconstraintlayout chain programmaticallywhy constraint layouts are betterconstraintlayout margin if goneconstraint layout boundstextview not showing in constraint layout

You May Also Like

15 Best Online Multiplayer Cricket Games for Android [2021]

Cricket is one of the biggest sports in the world and in…

Average Snowmobile Dimensions: Length, Width, and Height

*I may receive commissions for purchases made through the links in this…

10 Best Laptop for Accounting Students | laptops for quickbooks

As a designer, draftsman or mechanical and structural engineer, you must be…

7 Difference Between Xiaomi and Redmi Phones

Not many people know that Xiaomi started out as a software company.…