歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android: 仿Launcher Workspace左右滑動控件

Android: 仿Launcher Workspace左右滑動控件

日期:2017/3/1 11:09:27   编辑:Linux編程

修改Launcher的Workspace,去掉Drag相關的操作,精簡為一個支持左右滑動的控件

每屏中可以自由放置layout



主要的問題是對

@Override
public boolean dispathTouchEvent(MotionEvent ev) {}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {}

@Override
public boolean onTouchEvent(MotionEvent ev) {}

的理解,不然不好控制touch事件

代碼貼上,其實沒啥參考價值:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <com.mylauncher.Workspace
  3. xmlns:Android="http://schemas.android.com/apk/res/android"
  4. xmlns:launcher="http://schemas.android.com/apk/res/com.mylauncher"
  5. android:id="@+id/workspace"
  6. android:layout_width="match_parent"
  7. android:layout_height="match_parent"
  8. android:scrollbars="horizontal"
  9. android:fadeScrollbars="true"
  10. launcher:defaultScreen="0">
  11. <com.mylauncher.CellLayout android:background="#ff0000ff"
  12. android:id="@+id/cell1"
  13. android:layout_width="match_parent"
  14. android:layout_height="match_parent"
  15. android:orientation="vertical"
  16. >
  17. <TextView
  18. android:layout_width="fill_parent"
  19. android:layout_height="wrap_content"
  20. android:textSize="30sp"
  21. android:textStyle="bold"
  22. android:text="@string/screen1" />
  23. <Button
  24. android:layout_width="fill_parent"
  25. android:layout_height="wrap_content"
  26. android:textSize="30sp"
  27. android:textStyle="bold"
  28. android:text="@string/screen1" />
  29. </com.mylauncher.CellLayout>
  30. <com.mylauncher.CellLayout android:background="#ffff0000"
  31. android:id="@+id/cell2"
  32. android:layout_width="match_parent"
  33. android:layout_height="match_parent"
  34. android:orientation="vertical"
  35. >
  36. <TextView
  37. android:layout_width="fill_parent"
  38. android:layout_height="wrap_content"
  39. android:textSize="30sp"
  40. android:textStyle="bold"
  41. android:text="@string/screen2" />
  42. <Button
  43. android:layout_width="fill_parent"
  44. android:layout_height="wrap_content"
  45. android:textSize="30sp"
  46. android:textStyle="bold"
  47. android:text="@string/screen2" />
  48. </com.mylauncher.CellLayout>
  49. <com.mylauncher.CellLayout android:background="#ff00ff00"
  50. android:id="@+id/cell3"
  51. android:layout_width="match_parent"
  52. android:layout_height="match_parent"
  53. android:orientation="vertical"
  54. >
  55. <TextView
  56. android:layout_width="fill_parent"
  57. android:layout_height="wrap_content"
  58. android:textSize="30sp"
  59. android:textStyle="bold"
  60. android:text="@string/screen3" />
  61. <Button
  62. android:layout_width="fill_parent"
  63. android:layout_height="wrap_content"
  64. android:textSize="30sp"
  65. android:textStyle="bold"
  66. android:text="@string/screen3" />
  67. </com.mylauncher.CellLayout>
  68. </com.mylauncher.Workspace>
Copyright © Linux教程網 All Rights Reserved