Android allows you to dynamically drag images as needed
Application Scenario: mini games
It is difficult to use imageview to implement dynamic drag-and-drop images for android. Here we introduce a method to use button:
1. There are any interface elements. The user selects one to drag on the screen. After dragging, the image elements stay at the actionup position;
2. First, set any button element on the interface and Set background:
Android: background = "@ drawable/bgall"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: scrollbars = "none"
Android: listSelector = "#00000000">
Android: background = "@ drawable/pebble"
Android: layout_centerHorizontal = "true"
Android: layout_centerVertical = "true"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"/>
...
3. The main activity requires implements OnTouchListener,
TouchCrowListener = new OnTouchListener ()
{
Int [] temp = new int [] {0, 0 };
Int oldxxx = 0;
Int oldyyy = 0;
Public boolean onTouch (View v, MotionEvent event)
{
Int eventaction = event. getAction ();
Int x = (int) event. getRawX ();
Int y = (int) event. getRawY ();
......
// Configure //----------------------------------------------------------------------------------------------
V. layout (x-temp [0], y-temp [1], x + v. getWidth ()-temp [0], y-temp [1] + v. getHeight ());
V. postInvalidate ();
4. button is easy to control because the layout attribute and postInvalidate method can be used, and the background setting can also achieve the Display Effect of imageview.
The above functions in the crow Drinking Water games have to use the http://openbox.mobilem.360.cn/index/d/sid/162210 http://zhushou.360.cn/detail/index/soft_id/162210]
Crow and Shi zier both use the button + to set the background of btton.