所以我有这个textview“To”,一个用于输入联系人的edittext和一个搜索按钮,用于在一行中搜索所有联系人. textview和按钮都很好,但问题是edittext很小,我希望它占用所有剩余的空间.这是代码:
- <RelativeLayout
- android:layout_height="wrap_content"
- android:layout_width="fill_parent"
- android:paddingTop="10dp">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="To: "
- android:textColor="#000000"
- android:paddingTop="10dp"
- android:layout_toLeftOf="@+id/editText_recipient"
- android:layout_alignParentLeft="true"
- android:layout_marginLeft="10dp"/>
- <EditText
- android:id="@+id/editText_recipient"
- android:layout_height="wrap_content"
- android:layout_width="wrap_content"
- android:hint="Enter Number"
- android:inputType="number"
- android:textSize="12sp"
- android:layout_toLeftOf="@+id/button_recipient_picker"
- android:layout_marginLeft="5dp"/>
- <Button
- android:id="@+id/button_recipient_picker"
- android:layout_height="wrap_content"
- android:layout_width="wrap_content"
- android:text="Browse .."
- android:layout_alignParentRight="true"
- android:layout_marginLeft="5dp"
- android:layout_marginRight="5dp"
- android:onClick="doLaunchContactPicker"/>
- </RelativeLayout>
解决方法
- <LinearLayout
- android:layout_height="wrap_content"
- android:layout_width="fill_parent"
- android:paddingTop="10dp">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="To: "
- android:textColor="#000000"
- android:paddingTop="10dp"
- android:layout_marginLeft="10dp"/>
- <EditText
- android:id="@+id/editText_recipient"
- android:layout_height="wrap_content"
- android:layout_width="wrap_content"
- android:hint="Enter Number"
- android:inputType="number"
- android:textSize="12sp"
- android:layout_marginLeft="5dp"
- android:layout_weight="1"
- />
- <Button
- android:id="@+id/button_recipient_picker"
- android:layout_height="wrap_content"
- android:layout_width="wrap_content"
- android:text="Browse .."
- android:layout_marginLeft="5dp"
- android:layout_marginRight="5dp"
- android:onClick="doLaunchContactPicker"/>
- </LinearLayout>
使用此布局,我将您的布局转换为线性(水平默认).并为editText添加了layout_weight,它将占用剩余的空间.