zoukankan      html  css  js  c++  java
  • OnTouchListener

    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;
                }
            });
    
        }
    }
  • 相关阅读:
    List Available DBCC Commands
    DBCC
    Oracle Shared Pool机制之——Latches, Locks, Pins and Mutexes
    新春寄语——令人期待的2018
    Oracle Shared Pool之Library Cache
    Linux NTP服务配置 for Oracle RAC
    Oracle 12c启动时PDBs的自动打开
    Oracle RAC时间同步(NTP/CTSS)
    Oracle 11g后台进程一览表
    Selenium WebDriver-通过断言页面是否存在某些关键字来确定页面按照预期加载
  • 原文地址:https://www.cnblogs.com/excellencesy/p/9007968.html
Copyright © 2011-2022 走看看