歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

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>  
Copyright © Linux教程網 All Rights Reserved