我使用相对布局时候
    <Button
        android:id="@+id/scan_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"       
        android:text="Scan..." />
    
    <Button
        android:id="@+id/con_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:text="Connect" />现在这两个按钮已经水平一起摆放, 我想让这两个按钮各占屏幕一半摆放. 应如何修改这个xml文件?

解决方案 »

  1.   

    你把 hight 设置成 match_parent试试看
      

  2.   

    简单的很啊<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal" >    <Button
            android:id="@+id/scan_button"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Scan..." />    <Button
            android:id="@+id/con_button"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Connect" /></LinearLayout>
      

  3.   

    LS的是线性布局. 我用的是相对布局. 我里面都没有找到layout_weight这一项.
      

  4.   

    你就不能在两个button外面套一层linerlayout???
      

  5.   

    同意二楼,用android:layout_weight,设置为相同的数值。
      

  6.   

    相对布局,哪来的这个啊,哈哈哈,楼主问这个问题很有代表性的<RelativeLayout 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="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal" >        <Button
                android:id="@+id/scan_button"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Scan..." />        <Button
                android:id="@+id/con_button"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Connect" />
        </LinearLayout></RelativeLayout>
      

  7.   

    找到了这个,http://pcq019.blog.163.com/blog/static/12460232320122155651430/。
      

  8.   

    我按钮下面想放listview
    <ListView
        android:id="@+id/ListView01"     
        android:dividerHeight="5dp"
        android:textSize="20dip" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/scan_button" 
        android:layout_marginTop="20dp"
        android:layout_marginBottom="20dp"
    现在这么写发现listview与 button在一栏上了. listview应该如何写比较合适?
      

  9.   

    你看下父布局的android:orientation方式,不知道android:layout_below="@+id/scan_button"这个有没有效果...
      

  10.   

    我已经用了 android:layout_below="@+id/scan_button"  
    没有效果. 不知道用哪个方式可以实现
      

  11.   

    让你看下父布局的android:orientation......
      

  12.   


    相对布局,哪来的这个啊,哈哈哈,楼主问这个问题很有代表性的百分比怎么用啊。嗨,开始看错了,当时看的你是相对布局,用weight还不可以,哈哈哈,那个设置为0很不错的,无需嵌套线性布局很不错
      

  13.   

    我现在用
    <LinearLayout        
        android:layout_width="match_parent"        
        android:layout_height="match_parent"       
        android:orientation="horizontal" > 
           
        <Button            
            android:id="@+id/scan_button"            
            android:layout_width="0dip"            
            android:layout_height="wrap_content"            
            android:layout_weight="1"            
            android:text="Scan..." />         
            
        <Button            
            android:id="@+id/con_button"            
            android:layout_width="0dip"            
            android:layout_height="wrap_content"            
            android:layout_weight="1"            
            android:text="Connect" />
        </LinearLayout>
        
    <ListView
        android:id="@+id/ListView01"     
        android:dividerHeight="5dp"
        android:textSize="20dip" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="80dp"
        android:layout_marginBottom="20dp"
        /> 
    将listview上面固定一个隔开距离实现。 但觉得很别扭,没找到其他办法