适应显示方向——调整大小和重新定位

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

为了支持横向模式,可以在res文件夹下创建一个新文件夹,并命名为layout-land(表示横向)。

hhhhhhhh.png

  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. <Button
  43. android:id="@+id/button6"
  44. android:layout_width="180px"
  45. android:layout_height="wrap_content"
  46. android:text="Top Middle"
  47. android:layout_centerVertical="true"
  48. android:layout_centerHorizontal="true"
  49. android:layout_alignParentTop="true" />
  50. <Button
  51. android:id="@+id/button7"
  52. android:layout_width="180px"
  53. android:layout_height="wrap_content"
  54. android:text="Bottom Middle"
  55. android:layout_centerVertical="true"
  56. android:layout_centerHorizontal="true"
  57. android:layout_alignParentBottom="true" />
  58.  
  59. </RelativeLayout>

运行效果

bbbbbbbbbbb.png

标签: Android

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号