mainActivity如下:

package cn.c;
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
/**
* 需求描述:
* ImageView加载网络图片,在点击ImageView的时候实现点击的效果
* 类似于本地图片的相关操作
* 实现方式:
* 对于ImageView实现OnTouchListener()处理其点击事件
* 在点击事件时改变ImageView控件的Alpha
* 注意问题:
* onTouch()中return true;否则只能监听到按下
* 不能监听到抬起
*
*/
public class MainActivity extends Activity {
private ImageView mImageView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
}
private void init(){
mImageView=(ImageView) findViewById(R.id.imageView);
//获取网络图片的过程,省略
//mImageView.setImageBitmap(bitmap from network);
mImageView.setOnTouchListener(new TouchListenerImpl());
}
private class TouchListenerImpl implements OnTouchListener{
public boolean onTouch(View v, MotionEvent event) {
ImageView imageView=(ImageView) v;
//按下
if (event.getAction()==MotionEvent.ACTION_DOWN) {
System.out.println("down down down ");
imageView.setAlpha(0);
imageView.invalidate();
}

//抬起
if (event.getAction()==MotionEvent.ACTION_UP||
event.getAction()==MotionEvent.ACTION_CANCEL) {
System.out.println("up up up ");
imageView.setAlpha(200);
imageView.invalidate();
}
return true;
}
}
}


main.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" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ImageView加载的是网络图片,在点击ImageView的时候实现点击的效果.类似于本地图片的相关操作"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
/>

<ImageView
android:id="@+id/imageView"
android:layout_width="80dip"
android:layout_height="80dip"
android:src="@drawable/ic_launcher"
android:layout_centerInParent="true"
/>

</RelativeLayout>


更多相关文章

  1. Android功能模块化之网络连接状态判断
  2. Android 自定义控件 改变图片颜色来实现类似selector点击更改颜
  3. android获取网络数据
  4. android:使用网络通信技术从客户端直接获取服务端的对象数据
  5. Android网络编程-----从服务器端获取xml数据并解析
  6. Android 实现从本地读取图片更改聊天背景
  7. android 打开系统相册得到路径 上传图片到php服务器
  8. Android中如何有效的加载图片
  9. 在Android的评论屏幕上实施网络呼叫的最佳做法如何?

随机推荐

  1. 对android中MIME类型的理解
  2. Android SDK Emulator: Compile Cyanogen
  3. android的线性布局
  4. android googlemap权限问题
  5. android双击事件
  6. 三款Android游戏源码
  7. Android shape 参数
  8. Android定义宽高比控件
  9. Android NDK Tools 下载链接大全
  10. android常用权限