修改Launcher的Workspace,去掉Drag相關的操作,精簡為一個支持左右滑動的控件
每屏中可以自由放置layout
主要的問題是對
@Override
public boolean dispathTouchEvent(MotionEvent ev) {}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {}
@Override
public boolean onTouchEvent(MotionEvent ev) {}
的理解,不然不好控制touch事件
代碼貼上,其實沒啥參考價值:
- <?xml version="1.0" encoding="utf-8"?>
-
-
- <com.mylauncher.Workspace
- xmlns:Android="http://schemas.android.com/apk/res/android"
- xmlns:launcher="http://schemas.android.com/apk/res/com.mylauncher"
- android:id="@+id/workspace"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:scrollbars="horizontal"
- android:fadeScrollbars="true"
- launcher:defaultScreen="0">
-
- <com.mylauncher.CellLayout android:background="#ff0000ff"
- android:id="@+id/cell1"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- >
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:textSize="30sp"
- android:textStyle="bold"
- android:text="@string/screen1" />
- <Button
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:textSize="30sp"
- android:textStyle="bold"
- android:text="@string/screen1" />
-
- </com.mylauncher.CellLayout>
-
- <com.mylauncher.CellLayout android:background="#ffff0000"
- android:id="@+id/cell2"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- >
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:textSize="30sp"
- android:textStyle="bold"
- android:text="@string/screen2" />
- <Button
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:textSize="30sp"
- android:textStyle="bold"
- android:text="@string/screen2" />
- </com.mylauncher.CellLayout>
-
- <com.mylauncher.CellLayout android:background="#ff00ff00"
- android:id="@+id/cell3"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- >
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:textSize="30sp"
- android:textStyle="bold"
- android:text="@string/screen3" />
- <Button
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:textSize="30sp"
- android:textStyle="bold"
- android:text="@string/screen3" />
- </com.mylauncher.CellLayout>
-
- </com.mylauncher.Workspace>