亚洲春色中文字幕久久久-三上亚,一吻二脱三床四吻胸,国产真实伦对白视频全集,在线毛片观看,精品成品入口黄网,国产毛aⅴ片久久久,亚洲AV色香蕉一区二区三区老师,萧皇后A级艳片,色情日本视频更新,99久久亚洲精品日本无码
標題:
安卓事件處理 顯示用戶觸摸持續時間的小程序源碼
[打印本頁]
作者:
dori
時間:
2020-12-15 20:14
標題:
安卓事件處理 顯示用戶觸摸持續時間的小程序源碼
本帖最后由 dori 于 2020-12-18 23:13 編輯
設計一個顯示用戶觸摸持續時間的小程序
運行成功:
3.PNG
(91.7 KB, 下載次數: 79)
下載附件
2020-12-15 20:13 上傳
4.PNG
(86.08 KB, 下載次數: 82)
下載附件
觸摸一定時間
2020-12-15 20:13 上傳
MainActivity.java文件:
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.view.MotionEvent;
import android.view.View.OnTouchListener;
public class MainActivity extends Activity implements OnTouchListener
{
private ImageView iv;
private EditText et;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//加載布局
setContentView(R.layout.activity_main);
iv=findViewById(R.id.iv);
et=findViewById(R.id.et);
iv.setOnTouchListener(this);
}
@Override
public boolean onTouch(View v,MotionEvent event){
// TODO Auto-generated method stub
long time=event.getEventTime()-event.getDownTime();//計算觸摸持續時間
String s = String.valueOf(time);
if(event.getActionMasked()==MotionEvent.ACTION_UP){
et.setText(s);
}
return true;
}
}
activity_main.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="觸摸時間:"/>
<EditText
android:id="@+id/et"
android:layout_width="200sp"
android:layout_height="wrap_content"
android:textColor="@color/colorAccent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="毫秒"/>
</LinearLayout>
<ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/background"/>
</LinearLayout>
事件處理.rar
(10.38 MB, 下載次數: 3)
2020-12-18 23:13 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.denmoz.com/bbs/)
Powered by Discuz! X3.1