Android - linear layout bringToFront ()

I have 4 buttons in my linear layout, and I need to transfer to the first first button.

Normal order

Button 1 | Button 2 | Button 3 | Button 4 

But when I call the button1.bringToFront () function, button 1 ends up like

  Button 2 | Button 3 | Button 4 | Button 1 

How can I solve this problem. The relative layout does not cause this problem, but I have to use LinearLayout, because the buttons will be arranged vertically, and I delete the button in some conditions.

thank

+5
android android-linearlayout
May 23 '13 at 16:28
source share
4 answers

LinearLayout does not work with the z axis, therefore, this is the name of linear . Try using RelativeLayout and then call bringToFront() to get the desired effect. With RelativeLayout you can call layout_alignBollow to arrange the views vertically. Or you can embed views and layouts, for example, in your LinearLayout socket three RelativeLayout within those that you can place in Buttons (be careful with this approach, because adding too many views can be bad).

+7
May 23 '13 at 16:41
source share

Since bringToFront messed up the LinearLayout order, I decided to use RelativeLayout and put the top view (the view I want on top) last in XML.

Example:

 <RelativeLayout ...> <ViewBelow android:layout_below="@+id/view_on_top" ... /> <!-- Last view in XML appears above other views on screen --> <ViewOnTop android:id="@+id/view_on_top" ... /> </RelativeLayout> 

In the specific case of this question, ViewOnTop will be Button 1, and ViewBelow will be a LinearLayout containing other buttons.

+1
Jul 10 '15 at 12:26
source share

make your layout by calling forceLayout () to disable layout re-layout.

0
Jan 19 '14 at 6:32
source share

If you need to work with the Z axis in LinearLayout, you can use the setTranslationZ function.

Example:

 yourView.setTranslationZ(100); 
0
Jan 29 '18 at 0:41
source share



All Articles