Freso图片缩放控件

Fresco图片库0.7.0版本 samples包内增加了两个lib项目,gestures与zoomable,根据名字就知道是手势控制,随后写了个例子来测试一下。

代码很简单:

  主要是使用 zoomable包内的ZoomableDraweeView

1.布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.facebook.samples.comparison.ZoomActivity"
    tools:showIn="@layout/activity_zoom">

    <com.facebook.samples.zoomable.ZoomableDraweeView
        android:id="@+id/zoomView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></com.facebook.samples.zoomable.ZoomableDraweeView>
</RelativeLayout>

2. 主要代码:

zoomView = (ZoomableDraweeView) findViewById(R.id.zoomView);
ZoomableController controller = new DefaultZoomableController(TransformGestureDetector.newInstance());
zoomView.setZoomableController(controller);
ImageRequest request = ImageRequest.fromUri(uri);
DraweeController draweeController = Fresco.newDraweeControllerBuilder()
        .setTapToRetryEnabled(true)
        .setOldController(zoomView.getController())
        .setImageRequest(request)
        .build();
GenericDraweeHierarchyBuilder hierarchyBuilder = new GenericDraweeHierarchyBuilder(getResources());
GenericDraweeHierarchy hierarchy = hierarchyBuilder
        .build();
zoomView.setHierarchy(hierarchy);
zoomView.setController(draweeController);


你可能感兴趣的:(Fresco)