布局视图组——ScrollView

作者:追风剑情 发布于:2015-7-13 21:25 分类:Android

ScrollView是一种特殊类型的FrameLayout,因为它可以使用户滚动显示一个占据的空间大于物理显示的视图列表。ScrollView只能包含一个子视图或视图组,通常是LinearLayout。

注意: 不要将ScrollView和ListView一起使用。ListView用来显示一个相关信息的列表并针对大列表的处理进行了优化。

因为EditText自动获得焦点,所以它会填充整个活动(因为高度被设为了600dp)。为了防止它获得焦点,在<LinearLayout>元素中添加下面两个属性:

android:focusable="true"

android:facusableInTouchMode="true"

有时候可能想让EditText自动获得焦点,但是不想让软件输入面板(键盘)自动显示(在实际设备上会自动显示)。为了防止键盘显示,在AndroidManifest.xml文件的<activity>元素中添加下面的属性:

android:windowSoftInputMode="stateHidden"

  1. <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. tools:context="${relativePackage}.${activityClass}" >
  6.  
  7. <LinearLayout
  8. android:layout_width="fill_parent"
  9. android:layout_height="wrap_content"
  10. android:orientation="vertical"
  11. android:focusable="true"
  12. android:focusableInTouchMode="true">
  13. <Button
  14. android:id="@+id/button1"
  15. android:layout_width="fill_parent"
  16. android:layout_height="wrap_content"
  17. android:text="Button 1" />
  18. <Button
  19. android:id="@+id/button2"
  20. android:layout_width="fill_parent"
  21. android:layout_height="wrap_content"
  22. android:text="Button 2" />
  23. <Button
  24. android:id="@+id/button3"
  25. android:layout_width="fill_parent"
  26. android:layout_height="wrap_content"
  27. android:text="Button 3" />
  28. <EditText
  29. android:id="@+id/txt"
  30. android:layout_width="fill_parent"
  31. android:layout_height="600dp"/>
  32. <Button
  33. android:id="@+id/button4"
  34. android:layout_width="fill_parent"
  35. android:layout_height="wrap_content"
  36. android:text="Button 4" />
  37. <Button
  38. android:id="@+id/button5"
  39. android:layout_width="fill_parent"
  40. android:layout_height="wrap_content"
  41. android:text="Button 5" />
  42. </LinearLayout>
  43. </ScrollView>

运行效果

ssssssssssssss.png

标签: Android

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号