android - Canont get a ImageView to center within a horizontal conatiner -


i hav e imageview inside horizontal container , have gravity set center. drawn right justified. image above it, not in horizontal canter centered.

am doing wrong, or objects inside horizontal container cannot centered??? code

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:background="#fff7f1d2"     android:orientation="vertical" >              <textview                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="in case of emergency: break glass"                android:layout_gravity="center"                 android:textstyle="bold"             />          <imageview                        android:id="@+id/butmenu"                    android:layout_width="wrap_content"             android:layout_height="wrap_content"                android:layout_gravity="center"             android:src="@drawable/menu"          />         <linearlayout      android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:background="#fff7f1d2"     android:orientation="horizontal" >        <imageview                         android:id="@+id/butmenu"                    android:layout_width="wrap_content"             android:layout_height="wrap_content"               android:layout_gravity="center"             android:src="@drawable/menu"          />             </linearlayout>       </linearlayout>  

you need add android:gravity="center"in parent container.

below updated layout

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:background="#fff7f1d2"     android:orientation="vertical" >      <textview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_gravity="center"         android:text="in case of emergency: break glass"         android:textstyle="bold" />      <imageview         android:id="@+id/butmenu"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_gravity="center"         android:src="@drawable/ic_launcher" />      <linearlayout         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:background="#fff7f1d2"         android:orientation="horizontal"          android:gravity="center">          <imageview             android:id="@+id/butmenu"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_gravity="center"             android:src="@drawable/ic_launcher" />     </linearlayout>  </linearlayout> 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -