android: gravity center_horizontal linearlayot doesn't work
11,360
Solution 1
try this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<LinearLayout
android:id="@+id/foo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="newItemOnclick"
android:orientation="vertical" >
<ImageView
android:id="@+id/id_new_big_list_item_image"
android:layout_width="50dip"
android:layout_height="50dip"
android:adjustViewBounds="true"
android:src="@drawable/photo1" />
</LinearLayout>
Solution 2
change second LinearLayout
width property to this android:layout_width="fill_parent"
it willl work...
Author by
yital9
Updated on June 05, 2022Comments
-
yital9 almost 2 years
my code
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:layout_width="fill_parent" > <LinearLayout android:id="@+id/foo" android:layout_height="wrap_content" android:layout_width="wrap_content" android:orientation="vertical" android:layout_gravity="center_horizontal" android:onClick="newItemOnclick"> <ImageView android:id="@+id/id_new_big_list_item_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:adjustViewBounds="true" android:src="@drawable/dom_logo_new" /> </LinearLayout> </LinearLayout>
but linearlayout foo align left, its not in the center. Whats wrong??
-
yital9 almost 12 yearsi need parent liner one background and in center foo liner with another background