clcurie_11 2013-08-28 05:39 采纳率: 6.7%
浏览 2290
已采纳

Android: linear layout 的问题

在我的linear layout 中有两个images,这两个 images 在布局的两端。但是当我改变屏幕方向时,cancel按钮又出现在中间。

<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>

不知道哪里出错了。
下面是 xml 文件:

<?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>
  • 写回答

1条回答

  • biaoguo819 2013-08-29 02:03
    关注

    楼主的LinearLayout中属性oriantation是horizontal,程序默认会进行横排布局,当一行放不下的时候,才会放到第二行去,直屏的时候,屏幕较窄,一行只能放下两个images,spinner就会放到下一行,横屏的时候,屏幕宽,images和spinner都会放到一行。建议楼主可以把两个images放到一个LinearLayout中

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB怎么通过柱坐标变换画开口是圆形的旋转抛物面?
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥30 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题