2012-06-29 36 views

回答

1

你必須有一個RelativeLayout是這樣的:

<RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <ImageView 
      android:src="@drawable/ic_launcher" 
      android:layout_alignTop="true" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_alignBottom="true"/> 
     <ImageView 
      android:id="@+id/top_mask" 
      android:src="@drawable/ic_launcher" 
      android:layout_alignTop="true" 
      android:layout_alignBottom="true"/> 
    </RelativeLayout> 

和代碼訪問上述掩模並設置其拖動事件是這樣的:

ImageView img = (ImageView)findViewById(R.id.top_mask); 
       img.setOnDragListener(new View.OnDragListener() { 
        @Override 
        public boolean onDrag(View v, DragEvent event) { 
         RelativeLayout.LayoutParams params = (android.widget.RelativeLayout.LayoutParams) v.getLayoutParams(); 
         params.topMargin = (int) event.getX(); 
         params.bottomMargin = (int) event.getY(); 
         v.setLayoutParams(params); 
         return false; 
        } 
       }); 

我還沒有測試過這段代碼。我只是寫了這個。我相信這一定幫你上手,甚至一個完整的解決方案:)

問候, Aqif哈米德