Centering an object in a LinearLayout (Android)

In StackOverFlow,

I am currently developing an android app and am facing a problem. The problem is that when I place two view elements under the parent (LinearLayout) it will not center one view to use the entire width of the parent. The reason for this (I believe) is that when the second view uses parent_fill, it already respects the width of the previous view. Therefore, it centers the "empty space". The code for the layout is below.

http://i.stack.imgur.com/byqG3.png

As you can tell, this is a simple layout. The problem is shown below.

http://puu.sh/jiKIV/4a30800776.png

The problem is the title bar (Max app) is not centered in the whole linear layout bar.

So my question is how do I create the center of the title across the entire linear layout, even if there are other views?

Thank,

Thomas.

+3


source to share


1 answer


Layout Layout is a concept you don't see here. Look at this:

http://developer.android.com/guide/topics/ui/layout/linear.html#Weight



In your case, you need to define the android:layout_weight=1

view that you want to center. This will make the presentation more important than anything else on the parent.

But the really best way to view in the center is to use RelativeLayout

instead LinearLayout

. Leveling up opportunities is much better

+2


source







All Articles