編輯:關於Android編程
public class MainActivity extends Activity implements OnTouchListener {
private long firstClick;
private long lastClick;
// 計算點擊的次數
private int count;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.ontourch).setOnTouchListener(this);
}
@Override
public boolean onTouch(View arg0, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// 如果第二次點擊 距離第一次點擊時間過長 那麼將第二次點擊看為第一次點擊
if (firstClick != 0 && System.currentTimeMillis() - firstClick > 300) {
count = 0;
}
count++;
if (count == 1) {
firstClick = System.currentTimeMillis();
} else if (count == 2) {
lastClick = System.currentTimeMillis();
// 兩次點擊小於300ms 也就是連續點擊
if (lastClick - firstClick < 300) {// 判斷是否是執行了雙擊事件
System.out.println(">>>>>>>>執行了雙擊事件");
}
}
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
break;
}
return true;
}
}
2.main_activity.xml實現:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/ontourch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
《Android動畫高手成長記》跳跳球效果
在介紹本文動畫效果實現之前,先來介紹屬性動畫相關的幾個知識點。ValueAnimator與ObjectAnimator。 Interpolator插值器與TypeEval
Android編程實現監聽EditText變化的方法
本文實例講述了Android編程實現監聽EditText變化的方法。分享給大家供大家參考,具體如下:監聽EditText中的內容的變化。在EditText沒有找到一個se
React Native自定義導航欄
經過之前的學習, 我們可以完成一個自定義導航欄了, 效果如下:我們需要創建一個 NaviBar.js 用來顯示頂部的導航欄, 還需要四個界面(Page1.js,Page2
android學習---SeekBar和RatingBar
SeekBar 拖動條:拖動條和滾動條類似,當是拖動條可以拖動滑塊改變進度 RatingBar 星級評分條:星級評分條與拖動條相似 See