android – 为什么EditText没有扩展到fill_parent

前端之家收集整理的这篇文章主要介绍了android – 为什么EditText没有扩展到fill_parent前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经编写了一个 XML代码,其中我想要将EditText扩展为适合父宽度.花了这么多时间后,找不到扩展EditText的方法.

这是我的XML:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent">
  6.  
  7. <TableLayout
  8. android:layout_width="fill_parent"
  9. android:layout_height="fill_parent"
  10. android:orientation="vertical">
  11.  
  12. <TableRow
  13. android:layout_marginLeft="10dp"
  14. android:layout_marginBottom="15dip">
  15. <TextView
  16. android:text="Comment"
  17. android:layout_width="match_parent"
  18. android:textStyle="bold"
  19. android:padding="3dip" />
  20. </TableRow>
  21.  
  22. <TableRow
  23. android:layout_marginLeft="10dp"
  24. android:layout_marginBottom="15dip">
  25. <EditText
  26. android:id="@+id/EditText02"
  27. android:layout_height="wrap_content"
  28. android:lines="5"
  29. android:gravity="top|left"
  30. android:inputType="textMultiLine"
  31. android:scrollHorizontally="false"
  32. android:minWidth="10.0dip"
  33. android:maxWidth="5.0dip"/>
  34. </TableRow>
  35.  
  36. <TableRow
  37. android:layout_marginLeft="10dp"
  38. android:layout_marginBottom="15dip"
  39. android:gravity="center">
  40. <Button
  41. android:id="@+id/cancel"
  42. android:text="Next" />
  43. </TableRow>
  44. </TableLayout>
  45. </LinearLayout>

我在这里做错了什么请帮帮我.

解决方法

在每一行添加一个额外的文本TextView.

代码可能会帮助您.

  1. <?xml version="1.0" encoding="UTF-8"?>
  2.  
  3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent">
  6.  
  7. <TableLayout
  8. android:layout_width="fill_parent"
  9. android:layout_height="fill_parent"
  10. android:stretchColumns="1"
  11. android:orientation="vertical">
  12.  
  13. <TableRow
  14. android:layout_width="fill_parent"
  15. android:layout_marginLeft="10dp"
  16. android:layout_marginBottom="15dip">
  17.  
  18. <TextView android:text="" />
  19.  
  20. <TextView
  21. android:text="Comment"
  22. android:layout_width="match_parent"
  23. android:layout_marginRight="10dp"
  24. android:textStyle="bold"
  25. android:padding="3dip" />
  26. </TableRow>
  27.  
  28. <TableRow
  29. android:layout_marginLeft="10dp"
  30. android:layout_marginBottom="15dip">
  31.  
  32. <TextView android:text="" />
  33.  
  34. <EditText
  35. android:id="@+id/EditText02"
  36. android:layout_width="match_parent"
  37. android:layout_height="wrap_content"
  38. android:layout_marginRight="20dp"
  39. android:lines="5"
  40. android:gravity="top|left"
  41. android:inputType="textMultiLine"
  42. android:scrollHorizontally="false" />
  43. </TableRow>
  44.  
  45. <TableRow
  46. android:layout_marginLeft="10dp"
  47. android:layout_marginBottom="15dip"
  48. android:gravity="center">
  49.  
  50. <TextView android:text="" />
  51.  
  52. <Button
  53. android:id="@+id/cancel"
  54. android:layout_marginRight="10dp"
  55. android:text="Next" />
  56. </TableRow>
  57. </TableLayout>
  58. </LinearLayout>

猜你在找的Android相关文章