Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put one View over other in RelativLlayout programmatically in Android?

I am programmatically creating view in Android. Parent layout is RelativLlayout and I'm adding two views in it. First is ListView and second is custom view. I want my second custom view to come on top of the list, but somehow it is getting hidden behind the ListView. How do I make sure that my custom view is on top.

like image 714
Chimu Avatar asked May 20 '13 08:05

Chimu


People also ask

How do I overlay one view over another android?

Just in case if you want to place a view on top of a ButtonView then use this; android:elevation="7dp" for the view which needs to be placed on top of the button. Thanks. It worked, but also worked with 1dp up for me.

Which is better LinearLayout or RelativeLayout?

Relativelayout is more effective than Linearlayout. From here: It is a common misconception that using the basic layout structures leads to the most efficient layouts. However, each widget and layout you add to your application requires initialization, layout, and drawing.

What is difference between LinearLayout and RelativeLayout?

Android provides the following ViewGroups or layouts: LinearLayout : is a ViewGroup that aligns all children in a single direction, vertically or horizontally. RelativeLayout : is a ViewGroup that displays child views in relative positions.


2 Answers

Views get placed in the order you add them to their parent views. The view added last will be on top. You might also want to try View.bringToFront() http://developer.android.com/reference/android/view/View.html#bringToFront()

like image 129
Megan Scott Avatar answered Oct 05 '22 20:10

Megan Scott


Try to use: View.bringToFront();

like image 40
onur taskin Avatar answered Oct 05 '22 20:10

onur taskin