Saturday 15 June 2013

android - why the right button can't on the right of parent like left button on the left of parent -



android - why the right button can't on the right of parent like left button on the left of parent -

<linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" android:text="left" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="center" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end" android:text="right" /> </linearlayout>

i know can utilize relativelayout , set alignparentright=true,to allow right button on right of parent,but want know,if utilize linearlayout,how can create right button on right of it's parent? help thanks

if have 3 or 2 kid can utilize framelayout instead of linearlayout. if want utilize linearlayout this

<linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="left" /> <button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="center" /> <button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="right" /> </linearlayout>

using framelayout parent

<framelayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left|center_vertical" android:text="left" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="center" /> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right|center_vertical" android:text="right" /> </framelayout>

why layout_gravity="right" not working horizontal linearlayout explained here

for horizontal linear layout next values create sense:

top center bottom

that because children of horizontal linear layout layed out horizontally 1 after other. thing can controlled using android:layout_gravity how kid view positioned vertically.

for vertical linear layout next values create sense:

left center right

that because children of vertical linear layout layed out vertically 1 below other. thing can controlled using android:layout_gravity how kid view positioned horizontally.

android layout-gravity

No comments:

Post a Comment