Android: 仿Launcher Workspace左右滑动控件


修改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.   
  3.       
  4.     <com.mylauncher.Workspace      
  5.     xmlns:Android="http://schemas.android.com/apk/res/android"  
  6.     xmlns:launcher="http://schemas.android.com/apk/res/com.mylauncher"      
  7.         android:id="@+id/workspace"  
  8.         android:layout_width="match_parent"  
  9.         android:layout_height="match_parent"  
  10.         android:scrollbars="horizontal"  
  11.         android:fadeScrollbars="true"  
  12.         launcher:defaultScreen="0">  
  13.           
  14.         <com.mylauncher.CellLayout   android:background="#ff0000ff"  
  15.             android:id="@+id/cell1"  
  16.             android:layout_width="match_parent"  
  17.             android:layout_height="match_parent"      
  18.             android:orientation="vertical"        
  19.             >  
  20.             <TextView      
  21.             android:layout_width="fill_parent"  
  22.             android:layout_height="wrap_content"  
  23.             android:textSize="30sp"                       
  24.             android:textStyle="bold"              
  25.             android:text="@string/screen1" />  
  26.             <Button        
  27.             android:layout_width="fill_parent"  
  28.             android:layout_height="wrap_content"  
  29.             android:textSize="30sp"                       
  30.             android:textStyle="bold"              
  31.             android:text="@string/screen1" />              
  32.               
  33.         </com.mylauncher.CellLayout>  
  34.           
  35.         <com.mylauncher.CellLayout   android:background="#ffff0000"  
  36.             android:id="@+id/cell2"  
  37.             android:layout_width="match_parent"  
  38.             android:layout_height="match_parent"    
  39.             android:orientation="vertical"            
  40.             >  
  41.             <TextView      
  42.             android:layout_width="fill_parent"  
  43.             android:layout_height="wrap_content"  
  44.             android:textSize="30sp"                       
  45.             android:textStyle="bold"              
  46.             android:text="@string/screen2" />       
  47.             <Button         
  48.             android:layout_width="fill_parent"  
  49.             android:layout_height="wrap_content"  
  50.             android:textSize="30sp"                       
  51.             android:textStyle="bold"              
  52.             android:text="@string/screen2" />                         
  53.         </com.mylauncher.CellLayout>      
  54.           
  55.         <com.mylauncher.CellLayout   android:background="#ff00ff00"  
  56.             android:id="@+id/cell3"  
  57.             android:layout_width="match_parent"  
  58.             android:layout_height="match_parent"     
  59.             android:orientation="vertical"        
  60.             >  
  61.             <TextView      
  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.             <Button         
  68.             android:layout_width="fill_parent"  
  69.             android:layout_height="wrap_content"  
  70.             android:textSize="30sp"                       
  71.             android:textStyle="bold"              
  72.             android:text="@string/screen3" />                    
  73.         </com.mylauncher.CellLayout>                
  74.           
  75.     </com.mylauncher.Workspace>  
  • 1
  • 2
  • 下一页

相关内容