歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android相對布局實現各種梅花效果

Android相對布局實現各種梅花效果

日期:2017/3/1 10:50:17   编辑:Linux編程

一、效果圖如下:


第一部是往drawable文件夾裡放一個圖片名為icon.png的圖片,首先在這裡說明Android只能放擴展名為png、jpg、gif的圖片;

然後編寫main.xml文件,代碼如下:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent" >
  5. <ImageButton
  6. android:layout_width="wrap_content"
  7. android:layout_height="wrap_content"
  8. android:background="@drawable/icon"
  9. android:layout_centerInParent="true"
  10. android:id="@+id/image0"/>
  11. <ImageButton
  12. android:layout_width="wrap_content"
  13. android:layout_height="wrap_content"
  14. android:background="@drawable/icon"
  15. android:layout_above="@id/image0"
  16. android:layout_toLeftOf="@id/image0"
  17. android:id="@+id/image1"/>
  18. <ImageButton
  19. android:layout_width="wrap_content"
  20. android:layout_height="wrap_content"
  21. android:background="@drawable/icon"
  22. android:layout_above="@id/image0"
  23. android:layout_toRightOf="@id/image0"
  24. android:id="@+id/image1"/>
  25. <ImageButton
  26. android:layout_width="wrap_content"
  27. android:layout_height="wrap_content"
  28. android:background="@drawable/icon"
  29. android:layout_below="@id/image0"
  30. android:layout_toLeftOf="@id/image0"
  31. android:id="@+id/image1"/>
  32. <ImageButton
  33. android:layout_width="wrap_content"
  34. android:layout_height="wrap_content"
  35. android:background="@drawable/icon"
  36. android:layout_below="@id/image0"
  37. android:layout_toRightOf="@id/image0"
  38. android:id="@+id/image1"/>
  39. </RelativeLayout>

說明:

android:layout_above 將該控件的底部 至於給定Id的控件 之上

android:layout_below 將該控件的頂部至於給定ID的控件之下

android:layout_toLeftOf 將該控件的右邊緣和給定ID的控件的左邊緣對齊

android:layout_toRightOf將該控件的左邊緣和給定ID的控件的右邊緣對齊

android:layout_alignBaseline將該 控件的baseline 和給定ID的控件 的baseline對齊

android:layout_alignBottom將該控件的底部邊緣與給定ID控件的底部邊緣對齊

android:layout_alignLeft將該控件的左邊緣與給定ID控件的左邊緣對齊

android:layout_alignRight將該控件的右邊緣與給定ID控件的右邊緣對齊

android:layout_alignTop將該控件的頂部邊緣與給定ID控件的頂部邊緣對齊

android:alignParentBottom 如果該值為true,則將該控件的底部和父控件的底部對齊

android:layout_alignParentLeft 如果該什為true, 則將該控件的左邊和父控件的左邊對齊

android:layout_alignParentRight 如果該什為true, 則將該控件的右邊和父控件的右邊對齊

android:layout_alignParentTop 如果該什為true, 則將該控件的頂部和父控件的頂部對齊

android:layout_centerHorizontal如果值為真,該控件將被至於水平方向的中央

android:layout_inParent如果值為真,該控件將被至於父控件水平方向和垂直方向的中央

android:layout_centerVertical如果值為真,該控件將被至於垂直方向的中央

Copyright © Linux教程網 All Rights Reserved