适应显示方向——锚定视图

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

注意: 当改变Android设备的方向时,当前活动实际上是先被销毁,然后再重新创建。

锚定——将视图锚定到屏幕的四条边是最容易的方法。当屏幕方向改变时,视图可以整齐的锚定于屏幕边缘。

  1. <RelativeLayout 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. <Button
  8. android:id="@+id/button1"
  9. android:layout_width="wrap_content"
  10. android:layout_height="wrap_content"
  11. android:text="Top Left"
  12. android:layout_alignParentLeft="true"
  13. android:layout_alignParentTop="true" />
  14. <Button
  15. android:id="@+id/button2"
  16. android:layout_width="wrap_content"
  17. android:layout_height="wrap_content"
  18. android:text="Top Right"
  19. android:layout_alignParentRight="true"
  20. android:layout_alignParentTop="true" />
  21. <Button
  22. android:id="@+id/button3"
  23. android:layout_width="wrap_content"
  24. android:layout_height="wrap_content"
  25. android:text="Bottom Left"
  26. android:layout_alignParentLeft="true"
  27. android:layout_alignParentBottom="true" />
  28. <Button
  29. android:id="@+id/button4"
  30. android:layout_width="wrap_content"
  31. android:layout_height="wrap_content"
  32. android:text="Bottom Right"
  33. android:layout_alignParentRight="true"
  34. android:layout_alignParentBottom="true" />
  35. <Button
  36. android:id="@+id/button5"
  37. android:layout_width="fill_parent"
  38. android:layout_height="wrap_content"
  39. android:text="Middle"
  40. android:layout_centerVertical="true"
  41. android:layout_centerHorizontal="true" />
  42.  
  43. </RelativeLayout>

运行效果

aaaaaa.png

标签: Android

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号