标签:void btn exit img length rri layout instance oncreate
界面的设置
<ImageView
android:id="@+id/picture"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center"/>
<Button
android:id="@+id/btn"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="out"/>
对其功能的实现:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
picture = (ImageView) findViewById(R.id.picture);
btn = (Button) findViewById(R.id.btn);
this.btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (btn.isClickable());
Toast.makeText(MainActivity.this,"再按一次退出按钮",Toast.LENGTH_LONG).show();
}
});
}
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_MOVE) {
float x = event.getX();
float y = event.getY();
String pos = "x坐标" + x + "y坐标" + y;
Toast.makeText(this, pos, Toast.LENGTH_LONG).show();
picture.setImageResource(R.drawable.youcaihua);
picture.setX(x - 100);
picture.setY(y - 100);
}
return super.onTouchEvent(event);
}
private long exitTime = 0;
标签:void btn exit img length rri layout instance oncreate
原文地址:http://www.cnblogs.com/liyuan1988/p/6596849.html