android – EditText不会填满余下的空间

前端之家收集整理的这篇文章主要介绍了android – EditText不会填满余下的空间前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
所以我有这个textview“To”,一个用于输入联系人的edittext和一个搜索按钮,用于在一行中搜索所有联系人. textview和按钮都很好,但问题是edittext很小,我希望它占用所有剩余的空间.这是代码
  1. <RelativeLayout
  2. android:layout_height="wrap_content"
  3. android:layout_width="fill_parent"
  4. android:paddingTop="10dp">
  5. <TextView
  6. android:layout_width="wrap_content"
  7. android:layout_height="wrap_content"
  8. android:text="To: "
  9. android:textColor="#000000"
  10. android:paddingTop="10dp"
  11. android:layout_toLeftOf="@+id/editText_recipient"
  12. android:layout_alignParentLeft="true"
  13. android:layout_marginLeft="10dp"/>
  14. <EditText
  15. android:id="@+id/editText_recipient"
  16. android:layout_height="wrap_content"
  17. android:layout_width="wrap_content"
  18. android:hint="Enter Number"
  19. android:inputType="number"
  20. android:textSize="12sp"
  21. android:layout_toLeftOf="@+id/button_recipient_picker"
  22. android:layout_marginLeft="5dp"/>
  23. <Button
  24. android:id="@+id/button_recipient_picker"
  25. android:layout_height="wrap_content"
  26. android:layout_width="wrap_content"
  27. android:text="Browse .."
  28. android:layout_alignParentRight="true"
  29. android:layout_marginLeft="5dp"
  30. android:layout_marginRight="5dp"
  31. android:onClick="doLaunchContactPicker"/>
  32. </RelativeLayout>

解决方法

  1. <LinearLayout
  2. android:layout_height="wrap_content"
  3. android:layout_width="fill_parent"
  4. android:paddingTop="10dp">
  5. <TextView
  6. android:layout_width="wrap_content"
  7. android:layout_height="wrap_content"
  8. android:text="To: "
  9. android:textColor="#000000"
  10. android:paddingTop="10dp"
  11. android:layout_marginLeft="10dp"/>
  12. <EditText
  13. android:id="@+id/editText_recipient"
  14. android:layout_height="wrap_content"
  15. android:layout_width="wrap_content"
  16. android:hint="Enter Number"
  17. android:inputType="number"
  18. android:textSize="12sp"
  19. android:layout_marginLeft="5dp"
  20. android:layout_weight="1"
  21. />
  22. <Button
  23. android:id="@+id/button_recipient_picker"
  24. android:layout_height="wrap_content"
  25. android:layout_width="wrap_content"
  26. android:text="Browse .."
  27. android:layout_marginLeft="5dp"
  28. android:layout_marginRight="5dp"
  29. android:onClick="doLaunchContactPicker"/>
  30. </LinearLayout>

使用此布局,我将您的布局转换为线性(水平默认).并为editText添加了layout_weight,它将占用剩余的空间.

猜你在找的Android相关文章