Android中第三方控件PhotoView的基本使用
来源:互联网 发布:java volatile的用法 编辑:程序博客网 时间:2024/06/03 12:30
PhotoView的简介:
这是一个图片查看库,实现图片浏览功能,支持pinch(捏合)手势或者点击放大缩小。支持在ViewPager中翻页浏览图片。
MainActivity中:
这是一个图片查看库,实现图片浏览功能,支持pinch(捏合)手势或者点击放大缩小。支持在ViewPager中翻页浏览图片。
PhotoView 是一款扩展自Android ImageView ,支持通过单点/多点触摸来进行图片缩放的智能控件。功能实用和强大。
PhotoView的功能:
图片浏览查看
双指缩放
单点触摸缩放
图片缩放模式设置
基本用法:
导入jar包,布局XML里设置PhotoView
将ImageView传入PhotoViewAttacher
代码演示:
使用 PhotoView进行网络图片和本地图片的加载,缩放和点击事件处理
布局文件中:
<span style="background-color: rgb(255, 255, 255);"><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></span>
MainActivity中:
public class MainActivity extends Activity {private PhotoView iv_photo1;private PhotoView iv_photo2;@Overrideprotected 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() {@Overridepublic void onPhotoTap(View arg0, float arg1, float arg2) {Toast.makeText(MainActivity.this, "图片被点击了", 10).show();}});}}BaseApplication中:
/** * 加载网络图片时,需要对ImageLoader进行全局配置 * */public class BaseApplication extends Application {@Overridepublic 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>
效果:
photoview-library-1.2.2.jar
universal-image-loader-1.9.2_sources.jar
效果展示:
jar包及源码下载:
http://download.csdn.net/detail/zhaihaohao1/9432820
0 1
- Android中第三方控件PhotoView的基本使用
- Android中第三方控件PhotoView的基本使用
- Android中第三方控件gifView的基本使用
- 使用第三方图片缩放库PhotoView遇到的问题
- PhotoView的基本使用
- PhotoView的基本使用
- React Native 中如何使用Android的第三方控件以Android的弹幕为例
- 开发中使用控件----------第三方控件
- android 中 使用 第三方库AutoLayout动态设置控件的属性
- android中使用photoview第二次设置图片遮挡控件的处理方法
- Android第三方控件——百度地图的使用
- IOS OC中使用Swift的Charts第三方控件
- web中使用第三方控件
- 第三方控件使用
- Android 开源photoView的使用
- Android 开源photoView的使用
- Android viewpager+photoview的使用
- 第三方框架Masonry的基本使用
- Can not perform this action after onSaveInstanceState
- 编译osgcal
- 好用便捷的js日期时间控件代码下载
- layDate日历控件的调用
- 怎么将导航栏始终固定在窗口顶部,类似bootstrap 的navbar-fixed-top
- Android中第三方控件PhotoView的基本使用
- myBatis批量添加,修改和删除
- may be using a version of Gradle that does not contain the method.
- 理解Spring Boot
- (转)精益技术简历之道——改善技术简历的47条原则
- IOS开发之ASIHTTPRequest下载示例
- 基于Spring + Spring MVC + Mybatis 高性能web构建
- coredata简单使用
- Android定制实现上网限制