[英]How i can change postion of the button randomly in android by clicking the button
It gives me an error here that setX(int) is not defined though it is button type.它给了我一个错误,虽然 setX(int) 是按钮类型但未定义。
public class TouchMe extends Activity implements View.OnClickListener {
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tuchme);
btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(this);
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case (R.id.btn): {
Random r = new Random();
int x = r.nextInt(480 - buttonWidth);
int y = r.nextInt(800 - buttonHeight);
btn.setX(x); // give me error here that setX(int) is not defined
btn.setY(y); // is button type.
}
}
It gives me error here that setX(int) is not defined is button type.它给我的错误是 setX(int) 未定义为按钮类型。 please help me.请帮我。
View.setX() and View.setY() are only available as of API level 11 (Android 3.0 Honeycomb). View.setX()和 View.setY() 仅在 API 级别 11(Android 3.0 Honeycomb)中可用。 You have to set minSdkVersion and targetSdkVersion accordingly and compile against API level 11 if you want to use these methods.如果您想使用这些方法,您必须相应地设置minSdkVersion 和 targetSdkVersion并针对 API 级别 11 进行编译。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.