Animation on button

In my application there are nine buttons.When a button is touched it should move to a target location. This can be easily done had there been image instead of button using surfaceview. How to do this with buttons ?

EDIT

package com.amit.wozzle;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TextView;
import android.support.v4.app.NavUtils;

public class MainActivity extends Activity {
private Button b1;
private Button b2;
private Button b3;
private Button b4;
private Button b5;
private Button b6;
private Button b7;
private Button b8;
private Button b9;
private int xb=3;
private int yb=3;
private int xbl;
private int ybt;
private int x=3;
private int y=3;
private TextView tv55; 

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    b1 = (Button) findViewById(R.id.tv1);
    b2 = (Button) findViewById(R.id.tv2);
    b3 = (Button) findViewById(R.id.tv3);
    b4 = (Button) findViewById(R.id.tv4);
    b5 = (Button) findViewById(R.id.tv5);
    b6 = (Button) findViewById(R.id.tv6);
    b7 = (Button) findViewById(R.id.tv7);
    b8 = (Button) findViewById(R.id.tv8);
    b9 = (Button) findViewById(R.id.tv9);

    b2.setOnClickListener(new Glide());
    b3.setOnClickListener(new Glide());
    b4.setOnClickListener(new Glide());
    b5.setOnClickListener(new Glide());
    b6.setOnClickListener(new Glide());
    b7.setOnClickListener(new Glide());
    b8.setOnClickListener(new Glide());
    b9.setOnClickListener(new Glide());



}


class Glide implements View.OnClickListener {
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

        int[] loc ={0,0};
        b1.getLocationOnScreen(loc);
        int xw = b1.getWidth();

        int[] loc1={0,0};
        v.getLocationOnScreen(loc1);


        TableLayout.LayoutParams lp = (TableLayout.LayoutParams) v.getLayoutParams();
        lp.leftMargin = loc[0];
        lp.topMargin = loc[1];
        v.setLayoutParams(lp);
        v.invalidate();


    }


}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}


}

This results in force close. Logcat says

07-14 02:04:32.564: D/AndroidRuntime(310): Shutting down VM
07-14 02:04:32.564: W/dalvikvm(310): threadid=1: thread exiting with uncaught exception  (group=0x4001d800)
07-14 02:04:32.574: E/AndroidRuntime(310): FATAL EXCEPTION: main
07-14 02:04:32.574: E/AndroidRuntime(310): java.lang.ClassCastException:     android.widget.TableRow$LayoutParams
07-14 02:04:32.574: E/AndroidRuntime(310):  at com.amit.wozzle.MainActivity$Glide.onClick(MainActivity.java:81)
07-14 02:04:32.574: E/AndroidRuntime(310):  at android.view.View.performClick(View.java:2408)
07-14 02:04:32.574: E/AndroidRuntime(310):  at android.view.View$PerformClick.run(View.java:8816)
07-14 02:04:32.574: E/AndroidRuntime(310):  at android.os.Handler.handleCallback(Handler.java:587)
07-14 02:04:32.574: E/AndroidRuntime(310):  at android.os.Handler.dispatchMessage(Handler.java:92)
07-14 02:04:32.574: E/AndroidRuntime(310):  at android.os.Looper.loop(Looper.java:123)
07-14 02:04:32.574: E/AndroidRuntime(310):  at android.app.ActivityThread.main(ActivityThread.java:4627)
07-14 02:04:32.574: E/AndroidRuntime(310):  at java.lang.reflect.Method.invokeNative(Native Method)
07-14 02:04:32.574: E/AndroidRuntime(310):  at java.lang.reflect.Method.invoke(Method.java:521)
07-14 02:04:32.574: E/AndroidRuntime(310):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-14 02:04:32.574: E/AndroidRuntime(310):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-14 02:04:32.574: E/AndroidRuntime(310):  at dalvik.system.NativeStart.main(Native Method)

Answers


I think what you are missing is just to set the parameters in the position that you want the button to appear. Below is and example:

public class MyAppActivity extends Activity {    

TableLayout mLayout;
Button b1;  

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);       

    b1 = (Button) findViewById(R.id.viewMatched_btn);        
    b1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            TableLayout.LayoutParams layoutParams = (TableLayout.LayoutParams) b1.getLayoutParams();
            layoutParams.topMargin = 200;
            layoutParams.leftMargin = 200;              
            b1.setLayoutParams(layoutParams);

            if(mLayout == null) {
                mLayout = (TableLayout) b1.getParent();
            }

            mLayout.invalidate();
        }
    });        

  }
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/temps_holder"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<Button
    android:id="@+id/viewMatched_btn"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"               
    android:text="Button"
    android:textColor="#ffffffff" />

</TableLayout>

Hope that helps. Also if what you want is to create a custom animation you can take a look at this.


Need Your Help

how to find the radius of a cluster using DBSCAN

python cluster-analysis data-mining radius dbscan

I'm a newcomer, and wanna learn different techniques of DIP... So, I wanna find out the radius of a inter-cluster, I know DBSCAN take two parameters epsilon (radius of intra-cluster) and