Simple implementation of Android floating button, android floating button
Simple implementation of Android floating button
package com.example.doinbackground;import android.app.Activity;import android.os.Bundle;import android.view.MotionEvent;import android.view.View;import android.view.View.OnTouchListener;import android.widget.Button;public class MainActivity extends Activity {/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);final Button bn = (Button) findViewById(R.id.bn);bn.setOnTouchListener(new OnTouchListener() {int[] temp = new int[] { 0, 0 };public boolean onTouch(View v, MotionEvent event) {int eventaction = event.getAction();int x = (int) event.getRawX();int y = (int) event.getRawY();switch (eventaction) {case MotionEvent.ACTION_DOWN: // touch down so check if thetemp[0] = (int) event.getX();temp[1] = y - v.getTop();break;case MotionEvent.ACTION_MOVE: // touch drag with the ballv.layout(x - temp[0], y - temp[1], x + v.getWidth()- temp[0], y - temp[1] + v.getHeight());// v.postInvalidate();break;case MotionEvent.ACTION_UP:break;}return false;}});}}