要实现如图的布局:

这是在eclipse可视化窗口中的截图,但实际运行在Android设备上可能出现的问题有:

(1):当编辑图1中的最后一个EditText时,输入法的编辑界面会把底部的Button顶上去,遮挡住了最后一个EditText;

(2):图2中的控件太多,以至于无法一屏全部显示,导致底部的Button被挤下去,又无法滚动控件,导致无法操作Button;

解决方案:

以下为布局文件代码:

图  1:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="wrap_content"
  5. android:orientation="vertical" >
  6.  
  7. <ScrollView
  8. android:layout_width="fill_parent"
  9. android:layout_height="match_parent"
  10. android:layout_above="@+id/linearLayout1"
  11. android:fillViewport="true" >
  12.  
  13. <TableLayout
  14. android:id="@+id/table"
  15. android:layout_width="fill_parent"
  16. android:layout_height="wrap_content"
  17. android:stretchColumns="1" >
  18.  
  19. <TableRow>
  20.  
  21. <TextView
  22. android:layout_width="60dp"
  23. android:layout_height="wrap_content"
  24. android:text="@string/product_name" />
  25.  
  26. <EditText
  27. android:layout_height="wrap_content"
  28. android:hint="@string/product_name" >
  29. </EditText>
  30. </TableRow>
  31.  
  32. <TableRow>
  33.  
  34. <TextView
  35. android:layout_width="60dp"
  36. android:layout_height="wrap_content"
  37. android:text="@string/product_id" />
  38.  
  39. <EditText
  40. android:layout_height="wrap_content"
  41. android:hint="@string/product_id" >
  42. </EditText>
  43. </TableRow>
  44.  
  45. <TableRow>
  46.  
  47. <TextView
  48. android:layout_width="60dp"
  49. android:layout_height="wrap_content"
  50. android:text="@string/raise_company" />
  51.  
  52. <EditText
  53. android:layout_height="wrap_content"
  54. android:hint="@string/raise_company" >
  55. </EditText>
  56. </TableRow>
  57.  
  58. <TableRow>
  59.  
  60. <TextView
  61. android:layout_width="80dp"
  62. android:layout_height="wrap_content"
  63. android:text="@string/about_info" />
  64.  
  65. <EditText
  66. android:layout_height="wrap_content"
  67. android:layout_weight="2"
  68. android:hint="@string/about_quality_website" >
  69. </EditText>
  70. </TableRow>
  71. </TableLayout>
  72. </ScrollView>
  73.  
  74. <LinearLayout
  75. android:id="@+id/linearLayout1"
  76. android:layout_width="fill_parent"
  77. android:layout_height="wrap_content"
  78. android:layout_alignParentBottom="true"
  79. android:paddingBottom="0dp" >
  80.  
  81. <Button
  82. android:layout_width="70dp"
  83. android:layout_height="wrap_content"
  84. android:layout_weight="2"
  85. android:text="@string/edit" />
  86.  
  87. <Button
  88. android:layout_width="70dp"
  89. android:layout_height="wrap_content"
  90. android:layout_weight="2"
  91. android:text="@string/refer" >
  92. </Button>
  93. </LinearLayout>
  94.  
  95. </RelativeLayout>

图  2:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:id="@+id/view"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent" >
  6.  
  7. <RelativeLayout
  8. android:layout_width="fill_parent"
  9. android:layout_height="wrap_content"
  10. android:orientation="vertical" >
  11.  
  12. <ScrollView
  13. android:id="@+id/view1"
  14. android:layout_width="fill_parent"
  15. android:layout_height="fill_parent" >
  16.  
  17. <TableLayout
  18. android:id="@+id/table"
  19. android:layout_width="fill_parent"
  20. android:layout_height="wrap_content"
  21. android:stretchColumns="1" >
  22.  
  23. <TableRow>
  24.  
  25. <TextView
  26. android:layout_width="60dp"
  27. android:layout_height="wrap_content"
  28. android:text="@string/product_name" />
  29.  
  30. <EditText
  31. android:layout_height="wrap_content"
  32. android:hint="@string/product_name" >
  33. </EditText>
  34. </TableRow>
  35.  
  36. <TableRow>
  37.  
  38. <TextView
  39. android:layout_width="60dp"
  40. android:layout_height="wrap_content"
  41. android:text="@string/product_id" />
  42.  
  43. <EditText
  44. android:layout_height="wrap_content"
  45. android:hint="@string/product_id" >
  46. </EditText>
  47. </TableRow>
  48.  
  49. <TableRow>
  50.  
  51. <TextView
  52. android:layout_width="60dp"
  53. android:layout_height="wrap_content"
  54. android:text="@string/current_data" />
  55.  
  56. <EditText
  57. android:layout_height="wrap_content"
  58. android:hint="@string/current_data" >
  59. </EditText>
  60. </TableRow>
  61.  
  62. <TableRow>
  63.  
  64. <TextView
  65. android:layout_width="60dp"
  66. android:layout_height="wrap_content"
  67. android:text="@string/raise_company" />
  68.  
  69. <EditText
  70. android:layout_height="wrap_content"
  71. android:hint="@string/raise_company" >
  72. </EditText>
  73. </TableRow>
  74.  
  75. <TableRow>
  76.  
  77. <TextView
  78. android:layout_width="60dp"
  79. android:layout_height="wrap_content"
  80. android:text="@string/raise_man" />
  81.  
  82. <EditText
  83. android:layout_height="wrap_content"
  84. android:hint="@string/raise_man" >
  85. </EditText>
  86. </TableRow>
  87.  
  88. <TableRow>
  89.  
  90. <TextView
  91. android:layout_width="60dp"
  92. android:layout_height="wrap_content"
  93. android:text="@string/feed_name" />
  94.  
  95. <EditText
  96. android:layout_height="wrap_content"
  97. android:hint="@string/feed_name" >
  98. </EditText>
  99. </TableRow>
  100.  
  101. <TableRow>
  102.  
  103. <TextView
  104. android:layout_width="60dp"
  105. android:layout_height="wrap_content"
  106. android:text="@string/feed_element" />
  107.  
  108. <EditText
  109. android:layout_height="wrap_content"
  110. android:hint="@string/feed_element" >
  111. </EditText>
  112. </TableRow>
  113.  
  114. <TableRow>
  115.  
  116. <TextView
  117. android:layout_width="60dp"
  118. android:layout_height="wrap_content"
  119. android:text="@string/medicine" />
  120.  
  121. <EditText
  122. android:layout_height="wrap_content"
  123. android:hint="@string/medicine" >
  124. </EditText>
  125. </TableRow>
  126.  
  127. <TableRow>
  128.  
  129. <TextView
  130. android:layout_width="60dp"
  131. android:layout_height="wrap_content"
  132. android:text="@string/health_condition" />
  133.  
  134. <EditText
  135. android:layout_height="wrap_content"
  136. android:hint="@string/health_condition" >
  137. </EditText>
  138. </TableRow>
  139.  
  140. <TableRow>
  141.  
  142. <TextView
  143. android:layout_width="60dp"
  144. android:layout_height="wrap_content"
  145. android:text="@string/water_quality" />
  146.  
  147. <EditText
  148. android:layout_height="wrap_content"
  149. android:hint="@string/water_quality" >
  150. </EditText>
  151. </TableRow>
  152.  
  153. <TableRow>
  154.  
  155. <TextView
  156. android:layout_width="60dp"
  157. android:layout_height="wrap_content"
  158. android:text="@string/water_temperature" />
  159.  
  160. <EditText
  161. android:layout_height="wrap_content"
  162. android:hint="@string/water_temperature" >
  163. </EditText>
  164. </TableRow>
  165.  
  166. <TableRow>
  167.  
  168. <TextView
  169. android:layout_width="60dp"
  170. android:layout_height="wrap_content"
  171. android:text="@string/record" />
  172.  
  173. <EditText
  174. android:layout_height="wrap_content"
  175. android:hint="@string/record" >
  176. </EditText>
  177. </TableRow>
  178. </TableLayout>
  179. </ScrollView>
  180.  
  181. <LinearLayout
  182. android:layout_width="fill_parent"
  183. android:layout_height="wrap_content"
  184. android:layout_below="@+id/view1" >
  185.  
  186. <Button
  187. android:layout_width="70dp"
  188. android:layout_height="wrap_content"
  189. android:layout_weight="2"
  190. android:text="@string/edit" />
  191.  
  192. <Button
  193. android:layout_width="70dp"
  194. android:layout_height="wrap_content"
  195. android:layout_weight="2"
  196. android:text="@string/refer" >
  197. </Button>
  198. </LinearLayout>
  199. </RelativeLayout>
  200.  
  201. </ScrollView>

需要说明的是:图一结构为:

图二结构为:

图二没有遮挡的问题,所以没有去修改它

结束语:关于Android中布局文件的滚动和控件遮挡问题已经描述和解决,作为一篇记录学习过程的文章,也希望能够帮助别人一起学习。

附上的代码,如果你喜欢,欢迎拿去,顺便,如果你把它完善的根据完美漂亮,也希望你反馈到这里  ^_^

Android 布局 中实现适应屏幕大小及组件滚动的更多相关文章

  1. 在Eclipse Android中设置模拟器屏幕大小

    在Eclipse Android中设置模拟器屏幕大小是本文要介绍的内容,主要是来了解并学习Eclipse Android中模拟器的设置,具体关于Eclipse Android内容的详解来看本文. 方法 ...

  2. Android布局中的空格以及占一个汉字宽度的空格的实现

    在Android布局中进行使用到空格,以便实现文字的对齐.那么在Android中如何表示一个空格呢? 空格:  窄空格:  一个汉字宽度的空格:   [用两个空格(  )占一个汉字的宽度时,两个空格比 ...

  3. Android布局中的空格以及占一个汉字宽度的空格,实现不同汉字字数对齐

    前言 在Android布局中进行使用到空格,以便实现文字的对齐.那么在Android中如何表示一个空格呢? 空格: (普通的英文半角空格但不换行) 窄空格:   (中文全角空格 (一个中文宽度))   ...

  4. android布局中使用include及需注意点

    在android布局中,使用include,将另一个xml文件引入,可作为布局的一部分,但在使用include时,需注意以下问题: 一.使用include引入 如现有标题栏布局block_header ...

  5. Android布局中的layout_weight和weightSum属性的详解及使用

    由于Android设备的尺寸大小不一,种类繁多,当我们在开发应用的时候就要考虑屏幕的适配型了,尽可能让我们的应用适用于主流机型的尺寸,这样我们的应用不会因为尺寸不同而不美观,解决屏幕适配问题的方法有很 ...

  6. Android针对不同的手机屏幕大小设计图片资源与编码

    注:本文转载于:http://blog.csdn.net/welovesunflower/article/details/7930248 一些术语 Screen Size 屏幕尺寸: 实际的物理尺寸, ...

  7. 【转】在Android布局中使用include和merge标签

    内容转自:http://fengweipeng1208.blog.163.com/blog/static/21277318020138229754135/ 在我们开发android布局时,经常会有很多 ...

  8. Android布局中涉及的一些属性

    Android:gravity属性 线性布局常见的就是利用LinearLayout进行布局,其中有个比较重要的属性就是android:gravity,在官方文档中是这么描述这个属性的:指定一个元素怎么 ...

  9. android 布局中 layout_gravity、gravity、orientation、layout_weight

    线性布局中,有 4 个及其重要的参数,直接决定元素的布局和位置,这四个参数是 android:layout_gravity ( 是本元素相对于父元素的重力方向 ) android:gravity (是 ...

随机推荐

  1. iOS修改声明为readonly的属性值

    本文讨论的是,对于类中声明为 readonly 的属性值,我们就不可以修改其值了么?如何可以,那么如何修改呢? 为了便于说明,定义一个 ACLStudent 的类: ACLStudent.h @int ...

  2. Masonry+Infinite-Scroll实现无刷新无分页完美瀑布流(转)

    一.Masonry 是基于Jquery插件,用于对CSS布局的可移动层进行重新布局.Masonry愿意石工,可以这样形象的理解,页面上很多大小不一的移动层可以想象成散乱的石头,经过Masonry这个石 ...

  3. 粒子系统1:简介&工具使用

    直接使用工具来感受一下粒子系统的强大威力吧. 网络上有很多粒子编辑器,大多数都是收费的.magicalsoft提供了一个免费的粒子编辑器(该工具目前只有mac版本),界面如下: 我们将针对这个编辑器来 ...

  4. Hidden Markov Model

    Markov Chain 马尔科夫链(Markov chain)是一个具有马氏性的随机过程,其时间和状态参数都是离散的.马尔科夫链可用于描述系统在状态空间中的各种状态之间的转移情况,其中下一个状态仅依 ...

  5. eclipse 总是提示文件下载

    在首选项->phpeclipse web development ->brower preview default 勾选掉

  6. struts2.1笔记03:AOP编程和拦截器概念的简介

    1.AOP编程 AOP编程,也叫面向切面编程(也叫面向方面):Aspect Oriented Programming(AOP),是目前软件开发中的一个热点,也是Spring框架中的一个重要内容.利用A ...

  7. Objective-C基础笔记一

    这里开始了我OC旅程 花了8天的时间粗略的学习了新知识Objective-C(简称OC),虽然只是学习了其中的基础部分,但经过这一周的学习也算是入门了.对面向对象的封装.继承.多态以及其中所包含的方法 ...

  8. WIN2003服务器IIS下如何开启GZIP压缩

    在上一篇文章黑客流谈到了关于网页打开速度对SEO的影响,其中提到了网页开启Gzip压缩的好处,接下来我来和大家分享一下WINDOWS系统IIS服务器下如何开启Gzip压缩. 首先我们来了解一下什么是G ...

  9. MapReduce按照两个字段对数据进行排序

    按照k2排序,要求k2必须是可以比较的,即必须实现WritableComparable接口. 但是如果还想让别的字段(比如v2中的一些字段)参与排序怎么办? 需要重新定义k2....把需要参与排序的字 ...

  10. 关于启动 Eclipse 弹出“Failed to load the JNI shared library jvm.dll”错误的解决方法!