1

I am facing hardtime with linear layout, in my linear layout i have two images these images are in opposite ends, but when iam changing the screen orientation the cancel button is comming in the middle

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

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"          
            android:src="@drawable/askabud" />
        <ImageView
            android:id="@+id/fbcancel"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"         
            android:paddingLeft="200dp"
            android:src="@drawable/fbcancel" />
         <Spinner
            android:id="@+id/quesspinner"
            android:layout_width="50dp"
            android:layout_height="30dp"
            android:drawSelectorOnTop="true"
            android:entries="@array/fblist"
            android:visibility="gone" />

 </LinearLayout>

not sure where iam going wrong. Any help is appreciated.

here is my complete xml file

<?xml version="1.0" encoding="utf-8"?>


    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:background="#FFFFFF" >
        <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"          
            android:src="@drawable/askabud" />
        <ImageView
            android:id="@+id/fbcancel"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"         
            android:paddingLeft="200dp"
            android:src="@drawable/fbcancel" />
         <Spinner
            android:id="@+id/quesspinner"
            android:layout_width="50dp"
            android:layout_height="30dp"
            android:drawSelectorOnTop="true"
            android:entries="@array/fblist"
            android:visibility="gone" />

 </LinearLayout>

        <View
            android:layout_width="wrap_content"
            android:layout_height="0.7dip"
            android:background="#3b5998" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="165dp"
            android:orientation="horizontal" >

            <ImageView
                android:id="@+id/autodelete"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_alignRight="@+id/fbshare"
                android:src="@drawable/autodelete" />

            <Spinner
                android:id="@+id/spinner"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/autodelete"
                android:layout_alignTop="@+id/autodelete" 
                android:visibility="gone"
                android:entries="@array/fblist" />

            <EditText
                android:id="@+id/fbedittext"
                android:layout_width="wrap_content"
                android:layout_height="135dp"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_marginLeft="16dp"
                android:layout_toLeftOf="@+id/fbshare"
                android:background="@drawable/roundcorners"
                android:ems="10"
                android:hint="@string/fbhint"
                android:windowSoftInputMode="stateHidden"
                android:textSize="14sp" />

            <ImageView
                android:id="@+id/fbshare"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_alignTop="@+id/fbedittext"
                android:layout_marginRight="15dp"
                android:layout_marginLeft="5dp"
                android:paddingRight="5dp"
                android:src="@drawable/newfb1" />

            <ImageView
                android:id="@+id/fbpeople"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_above="@+id/autodelete"
                android:layout_alignLeft="@+id/fbshare"
                android:layout_marginBottom="18dp"
                android:src="@drawable/people2" />

        </RelativeLayout>

        <TextView
            android:id="@+id/placeName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="gone"
            android:paddingTop="15dp"
            android:paddingLeft="10dp" 
            android:textColor="#000000"
            android:textStyle="bold"  />

        <TextView
            android:id="@+id/placeAddress"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="gone"
            android:paddingTop="10dp"
            android:paddingLeft="10dp"
            android:textColor="#000000" 
            android:textStyle="bold" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingTop="5dp"
            android:text="@string/fbtext"
            android:textColor="#000000"
            android:paddingLeft="10dp"
            android:paddingBottom="10dp" />
    </LinearLayout>
4

2 回答 2

0

but when iam changing the screen orientation the cancel button is comming in the middle

This is a little bit vague explanation of what is happening.

I'm guessing switching from landscape to portrait?

You aren't explaining how you want it to look and how it looks now. (In portrait and landscape). There don't seem to be an error, so if you want us to help you without us having to recreate all your code and strings and values.

Have you tried changing the paddingLeft of your cancelButton. It seems in portrait mode, it can be possible there isn't enough space to put those two imageviews next to each other, effectively pushing the other bottom and 200dp away from the left side.

于 2013-02-21T11:00:01.240 回答
0

Edit:

Try this

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

  <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         android:layout_gravity="left"    >
        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"  
            android:src="@drawable/ic_launcher" />
        </LinearLayout>
        <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
         android:gravity="right"
         >
        <ImageView
            android:id="@+id/fbcancel"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"         
            android:src="@drawable/ic_launcher" />
        </LinearLayout>
         <Spinner
            android:id="@+id/quesspinner"
            android:layout_width="50dp"
            android:layout_height="30dp"
            android:drawSelectorOnTop="true"
            android:visibility="gone" />

 </LinearLayout>

According to your requirement it will work...

Try to design separately for the land scape mode. You can do that by creating the file of same name in the directory res/layout-land. If you don't have a separate design for the Land scape than fix your Screen orientation to Potrait mode. You can do that in Activity level as well as in Application level. To set the fixed orientation use android:screenOrientation="portrait"

于 2013-02-21T11:05:04.147 回答