Android Killer
Android Killer

Reputation: 18509

Which Layout supports android:layout_gravity?

I came through many examples in internet.I found that neither Relative Layout nor Linear Layout supports android:layout_gravity.By it I mean the views inside these layouts does not support android:layout_gravity attribute. So any one having idea which layout supports android:layout_gravity and how to use it in better way?

Upvotes: 0

Views: 284

Answers (2)

Android-Droid
Android-Droid

Reputation: 14585

Actually if you use RelativeLayout you don't need to use layout_gravity.Better way to position your layout's elements are android. Here you can get a good explanation how to use RelativeLayout.

Upvotes: 0

Alec B. Plumb
Alec B. Plumb

Reputation: 2490

Children (that is, direct descendants in the View hierarchy) of LinearLayout do use layout_gravity (see LinearLayout.LayoutParams), but only on the "secondary" axis. So, in a vertical LinearLayout, center_horiztonal will work, but center_vertical will do nothing.

Children of FrameLayout also support layout_gravity (see FrameLayout.LayoutParams).

Keep in mind that the layout_* parameters set values in a LayoutParams object provided by the view parent. So a layout_* parameter will only have an effect if the parent view supports the parameter.

Upvotes: 2

Related Questions