Android allows you to dynamically drag images as needed

Source: Internet
Author: User

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.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.