Application Scenario: mini-game
Android to implement the dynamic arbitrary drag and drop pictures, using ImageView implementation is difficult, here is a method to use the button:
1. The interface element has any, the user operation selects one to drag on the screen, after the drag completes the picture element to stay in the actionup position;
2. First set any button elements in the interface and set the background:
<relativelayout android:id= "@+id/main"
android:background= "@drawable/bgall"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent"
Android:scrollbars= "None"
Android:listselector= "#00000000" >
<button android:id= "@+id/btnfirst"
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 needs 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 ();
。。。。。。
//----------------------------------------------------------------------------------------------
v.layout (x-temp[0], y-temp[1], X + v.getwidth ()-temp[0], y-temp[1] + v.getheight ());
v.postinvalidate ();
4. The use of button is easy to control because the layout property and the Postinvalidate method can be used, and the background setting can also achieve imageview display effect.
The above features are used in Crows water games with "http://openbox.mobilem.360.cn/index/d/sid/162210 Http://zhushou.360.cn/detail/index/soft_id/ 162210 "
Crows and Pebbles are button+ by setting Btton background.
Android for dynamic arbitrary drag pictures