【发布时间】:2015-11-26 21:59:37
【问题描述】:
好的,在这里我有这样的xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_margin="30dp"
android:background="@drawable/backgroundblankred" >
<Button
android:id="@+id/button1"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@drawable/eeclevelfirstblackbuton" />
</RelativeLayout>
</RelativeLayout>
原来是这样的
按钮在布局内,所以我想让按钮在单击时变成这样
按钮每秒随机在布局内移动,而不是从布局中移出,这会使应用程序强制关闭
第二个问题,如何设置随机按钮移动的快慢?比如设置按钮每2秒随机移动一次并增加更快,是否可以设置按钮移动更快?
我现在只有这个代码
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){
//If clicked, Move the button randomly
}
});
任何人都可以帮助一些代码?提前致谢。
【问题讨论】:
标签: java android button random