Is it possible in ContraintLayout to hide/show a view when a dependent view is gone/visible?
Obviously it's possible by using CoordinatorLayout with a custom behavior or by using an wrapped layout, however the mentioned approaches involve additional layouts. I would like to see such an approach that doesn't introduce additional layouts
You should be able to group the views together using the new "group" feature of ConstraintLayout 1.1.x. See this posting on Medium.
Groups, like the Guidelines, are widgets with size 0. But Group helps to apply some action to a set of widgets. The most common case, is to control a visibility of a collection of widgets.
You can do this programmatically.
When you set the vivisiblity of a compounant in your code, change the visibility value of the dependent view.
Related
Is it possible to hide individual views inside a group of a constraint layout.
I tried and failed & ultimately moved that view outside the group.
I did not find any document mentioning this behaviour.
Any one who can confirm?
whats you used for hide a view means INVSIBLE that take space of component and visiblity GONE not take any space of component .. so other component will effect.
can you show me your current code that i can understand properly.
thanks
I want set visibility of several views programmatically. Is there some way to treat them as one single view(or viewgroup)?
Take a look at a new feature in ConstraintLayout "group". By grouping views in ConstraintLayout using this feature you can set their visibility as one. See this Medium Post.
Group
Groups, like the Guidelines, are widgets with size 0. But Group helps to apply some action to a set of widgets. The most common case, is to control a visibility of a collection of widgets.
I would work with a piece of layout that isn't shown, the user must scroll to see what I have did. How can I do it? Can I join 2 different layout in one? I prefer to collocate item as I do with default layout. If it can help, I use Android studio. I prefer use elements without code, adding them from palette. An example :
You can use two different layout in main relative layout & whenever u want child layout just set visibility.
You will want to use a ScrollView for this. From the documentation:
Layout container for a view hierarchy that can be scrolled by the user, allowing it to be larger than the physical display.
I read this here:
Android provides a number of ready-made views that you can use to
design and organize your layout. "Widgets" are views that provide a
visual (and interactive) elements for the screen, such as a button,
text field, checkbox, or just an image. "Layouts" are views derived
from ViewGroup that provide a unique layout model for its child views,
such as a linear layout, a grid layout, or relative layout. You can
also subclass the View and ViewGroup classes (or existing subclasses)
to create your own widgets and layouts and apply them to your activity
layout.
If I am not wrong, this means people can even design their own widgets and layouts? Does that ever happen? Any examples?
this means people can even design their own widgets and layouts?
Yes.
Does that ever happen?
Yes.
Any examples?
There are hundreds of examples out on the Android Arsenal alone. Just looking at a couple of columns of the recent items, there are the following custom widgets and containers:
material-drawer
Material Design Android Library
StarBar
AndroidProgressLayout
DiscreteSeekBar
Android-SingleInputForm
SunDate Picker
How do you exchange the indices of two children in a ViewGroup?
How do I use setLeft on a child view? It doesn't seem to be defined for objects of class View.
Edit.
Answer to #2 is that setLeft is only available from API11. Ditto setX.
You can remove all children and than add by required order. I'm not found another way.
IMHO the best way for reorganize layout is use RelativeLayout.
As I do this:
// prepare rules
lpTopLeft = new RelativeLayout.LayoutParams(minDimension/5, minDimension/5);
lpTopLeft.setMargins(minDimension/50, minDimension/50, minDimension/50, minDimension/50);
lpTopLeft.addRule(RelativeLayout.ALIGN_PARENT_TOP);
lpTopLeft.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
And now use prepared settings:
// rearrange child
bnReset.setLayoutParams(lpTopLeft);
I guess removing the views and re-inflating the layout is the only solution. Maybe you can try to use a ViewFlipper. I don't know if it's suitable for your case.
best solution:
flexbox-layout by Google
FexboxLayout is a library project which brings the similar capabilities of CSS Flexible Box Layout Module to Android.
Then you can set
layout_order
This attribute can change how the ordering of the children views are laid out. By default, children are displayed and laid out in the same order as they appear in the layout XML. If not specified, 1 is set as a default value.