OnTouchListener
2024-08-30 00:36:09
1.布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="helloworld.com.inspur.app4.MainActivity"> <TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="hah"
android:id="@+id/tv_1"
/>
<TextView android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="hahahh"
android:id="@+id/tv_2"
/>
</LinearLayout>
(2)逻辑代码的实现
package helloworld.com.inspur.app4; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast; public class MainActivity extends AppCompatActivity {
private TextView tv1;
private TextView tv2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv1=(TextView)findViewById(R.id.tv_1);
tv2=(TextView)findViewById(R.id.tv_2);
tv2.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction())
{
case MotionEvent.ACTION_UP:
Toast.makeText(MainActivity.this,"按下",Toast.LENGTH_SHORT).show();
break;
case MotionEvent.ACTION_MOVE:
Toast.makeText(MainActivity.this,"移动",Toast.LENGTH_SHORT).show();
break;
case MotionEvent.ACTION_DOWN:
Toast.makeText(MainActivity.this,"松开",Toast.LENGTH_SHORT).show();
break;
} return true;
}
}); }
}
最新文章
- 小白的CSS基础学习
- HighCharts绘制图表
- Swift 2.0初探
- zw版【转发&#183;台湾nvp系列Delphi例程】HALCON FillUp1
- jQuery对象和dom对象的辨析和相互转化
- [iOS基础控件 - 3.4] 汤姆猫
- 1218.3——init自定义
- 转载:MyEclipse安装插件的几种方法
- NSTimer的问题
- 读书笔记之《深入理解Java虚拟机》不完全学习总结
- 一个非常有用的函数—COALESCE
- #ifdef #else #endif #if #ifndef 的用法
- 洛谷P2144 [FJOI2007]轮状病毒
- Luogu P1919 【模板】A*B Problem升级版(FFT快速傅里叶_FFT
- Cpython解释器GIL-多线程执行流程
- 「2017 山东三轮集训 Day7 解题报告
- eclipse中编辑properties文件无法看到中文
- 目标检测--Spatial pyramid pooling in deep convolutional networks for visual recognition(PAMI, 2015)
- Hi3516CV300 sample ->; region
- yml转properties
热门文章
- bash shell命令与监测的那点事(三)
- leetcode 【 Rotate Image 】python 实现
- [netty4][netty-common]FastThreadLocal及其相关类系列
- 设置CMD默认代码页为65001或936
- 使用 htaccess 重写 url,隐藏查询字符串
- 菜鸟之路——机器学习之线性回归个人理解及Python实现
- MySQL误操作后如何快速恢复数据?
- iOS-文本段落样式NSMutableParagraphStyle与NSParagraphStyle的使用和一些富文本处理属性
- BZOJ 2818: Gcd(欧拉函数)
- CLion 使用笔记(三)