1.首先是范例代码,一个基本的ImageButton响应。

 1 package com.example.arlxsdemo;
 2 
 3 import android.graphics.Bitmap;
 4 import android.graphics.drawable.BitmapDrawable;
 5 import android.os.Bundle;
 6 import android.support.v7.app.ActionBarActivity;
 7 import android.view.MotionEvent;
 8 import android.view.View;
 9 import android.widget.Button;
10 import android.widget.ImageButton;
11 
12 public class abc extends ActionBarActivity{
13     private ImageButton Btn_collect;//声明
14     @Override
15     protected void onCreate(Bundle savedInstanceState) {
16         super.onCreate(savedInstanceState);
17         setContentView(R.layout.activity_main);
18         
19         Btn_collect=(ImageButton)findViewById(R.id.collect);//与布局文件的ImageButton绑定
20         
21         Btn_collect.setOnClickListener(Btn_collectOnClick);//监听点击事件
22         Btn_collect.setOnTouchListener(Btn_collectOnTouch);//监听触摸事件
23         
24     }
25     /**
26      * 点击响应
27      */
28        private ImageButton.OnClickListener Btn_collectOnClick=new ImageButton.OnClickListener(){
29             public void onClick(View v){
30                 
31             }
32         };  
33      /**
34       * 触摸响应
35      */
36         private ImageButton.OnTouchListener Btn_collectOnTouch=new ImageButton.OnTouchListener(){
37             public boolean onTouch(View v,MotionEvent event){
38                   if(event.getAction() == MotionEvent.ACTION_UP){  
39                   
40                   }   
41                   if(event.getAction() == MotionEvent.ACTION_DOWN){  
42                  
43                   }  
44                 return true;
45             }
46         };     
47 }
基本响应范例

相关文章:

  • 2021-09-21
  • 2021-08-08
  • 2021-08-13
  • 2022-12-23
  • 2021-09-14
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-14
  • 2021-11-23
  • 2021-12-09
  • 2021-10-10
  • 2021-06-16
相关资源
相似解决方案