How to adjust 3 ImageViews in a LinearLayout
I defined a LinearLayout:
<LinearLayout
android:id="@+id/top_menu"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:background="@drawable/backrepeat"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/topLeft"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="left"
android:src="@drawable/library_top_left">
</ImageView>
<ImageView
android:id="@+id/topMiddle"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center"
开发者_开发百科 android:src="@drawable/library_top_middle"/>
<ImageView
android:id="@+id/topRight"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="right"
android:src="@drawable/library_top_right"/>
</LinearLayout>
I'd like that one image is on the left side of the screen, one in the middle, and one on the right side. However all of them are on the left side. How can I fix that?
Try a relative layout, and instead of gravity, try android:layout_alignParentLeft=true, android:layout_centerInParent=true, android:layout_alignParentRight=true
<RelativeLayout
android:id="@+id/top_menu"
android:layout_width="fill_parent"
android:background="@drawable/backrepeat"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/topLeft"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:src="@drawable/library_top_left"/>
<ImageView
android:id="@+id/topMiddle"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/library_top_middle"/>
<ImageView
android:id="@+id/topRight"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:src="@drawable/library_top_right"/>
</RelativeLayout>
Put in android:layout_weight="1"
into each of the image views. Supply padding/margin to make it better.
Take a look at RelativeLayout.
精彩评论