Hey Guys i have a Question about how to make a button randomly move every second
the black tiles are a button
so i want to make it move randomly in every second or more fast
this is my xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/backgroundblank" >
<Button
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/black1" />
</RelativeLayout>
this is the code
public class tested extends Activity {
Button buttonblack;
int score=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.tested);
buttonblack = (Button)findViewById(R.id.black1);
buttonblack.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
//score+10(i dont know how to make score +10 if the button clicked)
//if the button clicked
//Do some logic here
}
});
if (score = 100){
//the speed of move are increase more fast
}
}
anyone can help me?
First you should get the screen size
Then you should get a random x and random y position for the button to go to so that its still on screen
Finally to make this happen every second
In on create run it like this
Activity onCreate use this code
Create method
if you want in particular time use Timer