I have 4 buttons in my linear layout and i need to bring to front first button.
Normal order is
Button 1 | Button 2 | Button 3 | Button 4
But when I call button1.bringToFront()
function , button1
is going to end like
Button 2 | Button 3 | Button 4 | Button 1
How can I solve this problem. Relative layout doesn't causes this problem but I have to use LinearLayout
because buttons will order vertically and I'm deleting a button in some conditions.
Thanks
bringToFront()” method will let you a perfect indicator view :) Also, there is another option to use a parent-children relationship views.
LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. You can specify the layout direction with the android:orientation attribute. Note: For better performance and tooling support, you should instead build your layout with ConstraintLayout.
android:weightSum. Defines the maximum weight sum. If unspecified, the sum is computed by adding the layout_weight of all of the children. This can be used for instance to give a single child 50% of the total available space by giving it a layout_weight of 0.5 and setting the weightSum to 1.0.
LinearLayout
doesn't work with the z-axis, hence, it's name linear
. Try using a RelativeLayout
and then call bringToFront()
to get the desired effect. With a RelativeLayout
you can call layout_alignBollow
to order the views vertically. Or you can nest views and layouts, for instance, within your LinearLayout
nest three RelativeLayout
within those you can place your Buttons
(be careful with this approach as adding too many views can be a bad thing).
If you have to work with z-axis in a LinearLayout, you may use setTranslationZ function.
Example:
yourView.setTranslationZ(100);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With