In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article focuses on "how to achieve button drag and drop restore function in Android", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "how to achieve button drag and drop restore function in Android"!
The specific code is as follows:
Public class MainActivity extends AppCompatActivity {private ImageButton ibOk; private int lastX; private int lastY; private int startLeft; private int startRight; private int startTop; private int startBottom; @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); ibOk = (ImageButton) findViewById (R.id.ib_ok) IbOk.setOnTouchListener (new View.OnTouchListener () {@ Override public boolean onTouch (View v, MotionEvent event) {int action = event.getAction (); / / get the phone's touch coordinates int x = (int) event.getX (); int y = (int) event.getY () Switch (action) {case MotionEvent.ACTION_DOWN:// press to get the initial position of the ball startLeft = ibOk.getLeft (); startRight = ibOk.getRight (); startTop = ibOk.getTop (); startBottom = ibOk.getBottom (); lastX = x; lastY = y; break Case MotionEvent.ACTION_MOVE:// moves, the ball follows the movement of the finger int offsetX = x-lastX; int offsetY = y-lastY; ibOk.layout (ibOk.getLeft () + offsetX, ibOk.getTop () + offsetY, ibOk.getRight () + offsetX, ibOk.getBottom () + offsetY); break Case MotionEvent.ACTION_UP:// when the finger is raised, return to the original position of the ball ibOk.layout (startLeft, startTop, startRight, startBottom); break;} return true;}}) What is Android? Android is a free and open source operating system based on the Linux kernel, mainly used in mobile devices such as smartphones and tablets, led and developed by Google and the Open Mobile Alliance.
At this point, I believe you have a deeper understanding of "how to achieve button drag and drop restore function in Android". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.