布局视图组——RelativeLayout

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

RelativeLayout可用于指定子视图相对于彼此之间是如何定位的。

每一个嵌入RelativeLayout中的视图都有使它与其他视图对齐的属性。这些属性如下:


  • layout_alignParentTop
  • layout_alignParentLeft
  • layout_alignLeft
  • layout_alignRight
  • layout_below
  • layout_centerHorizontal



  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:tools="http://schemas.android.com/tools"
  3. android:id="@+id/RLayout"
  4. android:layout_width="fill_parent"
  5. android:layout_height="fill_parent"
  6. tools:context="${relativePackage}.${activityClass}" >
  7.  
  8. <TextView
  9. android:id="@+id/lblComments"
  10. android:layout_width="wrap_content"
  11. android:layout_height="wrap_content"
  12. android:text="Comments"
  13. android:layout_alignParentTop="true"
  14. android:layout_alignParentLeft="true" />
  15. <EditText
  16. android:id="@+id/txtComments"
  17. android:layout_width="fill_parent"
  18. android:layout_height="170px"
  19. android:textSize="18sp"
  20. android:layout_alignLeft="@+id/lblComments"
  21. android:layout_below="@+id/lblComments"
  22. android:layout_centerHorizontal="true" />
  23. <Button
  24. android:id="@+id/btnSave"
  25. android:layout_width="165px"
  26. android:layout_height="wrap_content"
  27. android:text="Save"
  28. android:layout_below="@+id/txtComments"
  29. android:layout_alignRight="@+id/txtComments" />
  30. <Button
  31. android:id="@+id/btnCancel"
  32. android:layout_width="164px"
  33. android:layout_height="wrap_content"
  34. android:text="Cancel"
  35. android:layout_below="@+id/txtComments"
  36. android:layout_alignLeft="@+id/txtComments" />
  37.  
  38. </RelativeLayout>


运行效果

rrrrrrrrrr.png

标签: Android

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号