开发者

Which Layout supports android:layout_gravity?

开发者 https://www.devze.com 2023-04-07 14:24 出处:网络
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:lay

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 havi开发者_如何学运维ng idea which layout supports android:layout_gravity and how to use it in better way?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消