Reputation: 128428
I know I am doing a small mistake.
I am using LinearLayout and I want to place the "icon-image" at "Center". I am using the following code:
<LinearLayout
android:id="@+id/LinearLayout01"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="@+id/LinearLayout02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="0">
<ImageView
android:id="@+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon"
android:layout_gravity="center_vertical|center_horizontal|center">
</ImageView>
</LinearLayout>
<LinearLayout>
............
</LinearLayout>
</LinearLayout>
As you see above, I have also set layout_gravity
.
Now my problem is, if I set android:layout_width="wrap_context"
instead of "fill_parent" in Child Linear Layout (i.e. LinearLayout02) then it works fine. but then what should I do to set icon-image at Center while setting fill_parent?
Upvotes: 1
Views: 688
Reputation: 1939
Add this to LinearLayout02 to specify that its contents should be centered horizontally:
android:gravity="center_horizontal"
Upvotes: 2