Question

when I change the orientation of emulator the logo and menu icon don't move to the both end of the screen but it shows in the middle.

this is my code.

`

<LinearLayout 
android:layout_width="fill_parent"
android:layout_height="70dp"
android:gravity="center"
android:animateLayoutChanges="true">
    <ImageView 
    android:id="@+id/ivmainlogo"
    android:layout_width="120dp"
    android:layout_height="80dp"
    android:src="@drawable/alfadesign1"
    />

     <ImageView 
    android:id="@+id/ivmainmenu"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:src="@drawable/menu1"
    android:layout_marginLeft="120dp"/>

</LinearLayout>
</LinearLayout>`

here is the image of the result which get. enter image description here

please help me in this code, thank you.

Was it helpful?

Solution

OK after a lot of experimentation here is the solution.Try this code out.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
>

<LinearLayout 
 android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="horizontal">

<ImageView 
android:id="@+id/ivmainlogo"
android:layout_width="120dp"
android:layout_height="80dp"
android:src="@drawable/alfadesign1"
/>

</LinearLayout>
<LinearLayout 
 android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:gravity="right">

 <ImageView 
android:id="@+id/ivmainmenu"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/menu1"
/>

 </LinearLayout>
 </LinearLayout>

OTHER TIPS

You are making the gravity of linearLyout "center".

Make individual gravity of both Imageview to left and right respectively.

 <ImageView 
    android:id="@+id/ivmainlogo"
    android:layout_width="120dp"
    android:layout_height="80dp"
    android:gravity="left"
    android:src="@drawable/alfadesign1"
    />

     <ImageView 
    android:id="@+id/ivmainmenu"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:gravity="right"
    android:src="@drawable/menu1"
    android:layout_marginLeft="120dp"/>

Try this:

<LinearLayout 
 android:layout_width="fill_parent"
 android:layout_height="70dp"
 android:animateLayoutChanges="true">

<ImageView 
android:id="@+id/ivmainlogo"
android:layout_width="120dp"
android:layout_height="80dp"
android:gravity="left"
android:src="@drawable/alfadesign1"
/>

 <ImageView 
android:id="@+id/ivmainmenu"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/menu1"
android:layout_marginLeft="120dp"
android:gravity="right"/>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top