Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android - linear layout bringToFront()

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

like image 785
dracula Avatar asked May 23 '13 16:05

dracula


People also ask

What is android bringToFront?

bringToFront()” method will let you a perfect indicator view :) Also, there is another option to use a parent-children relationship views.

What is android linear layout?

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.

What is layout_weight and weightSum in android?

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.


2 Answers

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).

like image 103
chRyNaN Avatar answered Sep 22 '22 14:09

chRyNaN


If you have to work with z-axis in a LinearLayout, you may use setTranslationZ function.

Example:

yourView.setTranslationZ(100);
like image 40
Pablo Alfonso Avatar answered Sep 20 '22 14:09

Pablo Alfonso