PhotoDraweeView for Fresco

photoview支持图片的缩放,但是使用fresco加载图片时,photoview是不支持的,而PhotoDraweeView 是支持fresco的。

PhotoDraweeView for Fresco_第1张图片
使用:
1、添加依赖

compile 'me.relex:photodraweeview:1.1.0'
compile 'com.facebook.fresco:fresco:0.10.0'

2、布局


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:fresco="http://schemas.android.com/apk/res-auto"
              xmlns:tools="http://schemas.android.com/tools"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:gravity="center"
              android:orientation="vertical"
              android:paddingBottom="@dimen/activity_vertical_margin"
              android:paddingLeft="@dimen/activity_horizontal_margin"
              android:paddingRight="@dimen/activity_horizontal_margin"
              android:paddingTop="@dimen/activity_vertical_margin"
              tools:context=".view.MainActivity">

    <me.relex.photodraweeview.PhotoDraweeView
        android:id="@+id/pdv"
        android:layout_width="234dp"
        android:layout_height="350dp"
        fresco:actualImageScaleType="fitXY"/>

LinearLayout>

3、代码

public class MainActivity extends Activity {

    PhotoDraweeView mPdv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mPdv = (PhotoDraweeView) findViewById(R.id.pdv);
        setDataToPhotoView();
    }

    private void setDataToPhotoView() {
        final PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder();
        controller.setUri(Uri.parse("res://com.example.administrator.rxjavademo/" + R.mipmap.airport_map));
        controller.setOldController(mPdv.getController());
        controller.setControllerListener(new BaseControllerListener() {
            @Override
            public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
                super.onFinalImageSet(id, imageInfo, animatable);
                if (imageInfo == null || mPdv == null) {
                    return;
                }
                mPdv.update(imageInfo.getWidth(), imageInfo.getHeight());
            }
        });
        mPdv.setController(controller.build());
    }
}

你可能感兴趣的:(android,PhotoView)