<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" tools:context=".MainActivity" android:orientation="vertical" > <uk.co.senab.photoview.PhotoView android:id="@+id/iv_photo1" android:layout_width="match_parent" android:layout_height="wrap_content" /> <uk.co.senab.photoview.PhotoView android:id="@+id/iv_photo2" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout>
public class MainActivity extends Activity {
private PhotoView iv_photo1;
private PhotoView iv_photo2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv_photo1 = (PhotoView) findViewById(R.id.iv_photo1);
iv_photo2 = (PhotoView) findViewById(R.id.iv_photo2);
// localImage();
netImage();
}
/**
* 加载本地图片
*
*/
private void localImage() {
// 加载本地图片,缩放处理
try {
// 图片在asset目录中
InputStream is = getAssets().open("photo2.jpg");
Bitmap bm = BitmapFactory.decodeStream(is);
iv_photo1.setImageBitmap(bm);
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 加载网络图片
*/
private void netImage() {
ImageLoader loader = ImageLoader.getInstance();
loader.displayImage("https://www.baidu.com/img/bdlogo.png", iv_photo2);
iv_photo2.setOnPhotoTapListener(new OnPhotoTapListener() {
@Override
public void onPhotoTap(View arg0, float arg1, float arg2) {
Toast.makeText(MainActivity.this, "图片被点击了", 10).show();
}
});
}
}
/**
* 加载网络图片时,需要对ImageLoader进行全局配置
*
*/
public class BaseApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
initImagloader(getApplicationContext());
}
private void initImagloader(Context context) {
File cacheDir = StorageUtils.getOwnCacheDirectory(context,
"photoview/Cache");// 获取到缓存的目录地址
// 创建配置ImageLoader(所有的选项都是可选的,只使用那些你真的想定制),这个可以设定在APPLACATION里面,设置为全局的配置参数
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(
context)
// 线程池内加载的数量
.threadPoolSize(3).threadPriority(Thread.NORM_PRIORITY - 2)
.memoryCache(new WeakMemoryCache())
.denyCacheImageMultipleSizesInMemory()
.discCacheFileNameGenerator(new Md5FileNameGenerator())
// 将保存的时候的URI名称用MD5 加密
.tasksProcessingOrder(QueueProcessingType.LIFO)
.discCache(new UnlimitedDiscCache(cacheDir))// 自定义缓存路径
// .defaultDisplayImageOptions(DisplayImageOptions.createSimple())
.writeDebugLogs() // Remove for release app
.build();
// Initialize ImageLoader with configuration.
ImageLoader.getInstance().init(config);// 全局初始化此配置
}
}
<uses-permission android:name="android.permission.INTERNET"/> <application android:name="com.zhhandroid.BaseApplication" android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有