如题,我想在一行里,先放个文本框,再放个固定宽度的按钮。文本框宽度填满剩余的空间,能实现吗?

解决方案 »

  1.   

     fill_parent属性。 或者计算好屏幕宽度,因为按钮是固定宽度的,所以剩下的宽度全部给文本框,设置个dip绝对值
      

  2.   

    同意楼上的 给文本框设置match_parent属性,给按钮设置个绝对值的属性就可以。
      

  3.   

    木有march_parent属性,只有fill_parent和wrap_content属性
      

  4.   

    我试过了,按钮在文本框后面的话,fill_parent的文本框会占据整个一行的宽度,把按钮挤到屏幕外面去了。
      

  5.   

    其实最方便的就是在ADT里面xxx.xml预览页面拖控件就OK了,就和.net一样,最新的ADT很强大的
      

  6.   

    <?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="wrap_content" 
        android:orientation="horizontal"
        >    <EditText
            android:id="@+id/editText1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_toLeftOf="@+id/button1" >
        </EditText>    <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
    </LinearLayout>
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        >    <EditText
            android:id="@+id/editText1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_toLeftOf="@+id/button1" >
        </EditText>    <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:text="Button" />
    </RelativeLayout>
      

  7.   


        <EditText
            android:id="@+id/editText1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_toLeftOf="@+id/button1" >
        </EditText>
    注意layout_weight="1"就是布局比重的重点。
      

  8.   

    <LinearLayout android:weightSum="5"><EditText layout_weight="1"/>
    设为1就代表占父的1/5   设为5就全占  ;但是若还有其他的子和他并列,就会占父的全部 ,但是会给另外的子留下一部分空间来显示。