主MainActivity中的
public class MainActivity extends AppCompatActivity {
private Button button;
private Button image;
private ImageView imageView;
String path="http://pics.sc.chinaz.com/files/pic/pic9/201705/zzpic3847.jpg";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button= (Button) findViewById(R.id.button);
image= (Button) findViewById(R.id.button2);
imageView= (ImageView) findViewById(R.id.imageView);
button.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if(motionEvent.getAction()==MotionEvent.ACTION_DOWN){
//设置监听,对动作进行判断,然后做出相应的提示
Toast.makeText(MainActivity.this,"已经按下",Toast.LENGTH_SHORT).show();
}else if(motionEvent.getAction()==MotionEvent.ACTION_UP){
Toast.makeText(MainActivity.this,"已经抬起",Toast.LENGTH_SHORT).show();
}
return false;
}
});
image.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
ImageLoader.getInstance().displayImage(path,imageView,new imageAPP().getOptions());
return false;
}
});
}
}
MyApplication类中的
public class imageAPP extends Application {
@Override
public void onCreate() {
super.onCreate();
String path = Environment.getExternalStorageDirectory()+"/1507DPics";
File cacheDir = new File(path);
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
.threadPoolSize(3)
.threadPriority(100)
.memoryCacheExtraOptions(480,800)
.memoryCacheSize(2 * 1024 * 1024)
.diskCache(new UnlimitedDiskCache(cacheDir))
.diskCacheSize(50 * 1024 * 1024)
.diskCacheFileNameGenerator(new Md5FileNameGenerator())
.build();
ImageLoader.getInstance().init(config);
}
public static DisplayImageOptions getOptions(){
DisplayImageOptions options = new DisplayImageOptions.Builder()
.cacheInMemory(true)
.cacheOnDisk(true)
.displayer(new RoundedBitmapDisplayer(50))
.build();
return options;
}
}