Giter Site home page Giter Site logo

imagereview's Introduction

ImageReview

仿微信图片详情页面,可下拉关闭页面

效果如下

imagereview.gif

如何使用

compile 'com.jchou.android.imagereview:imagereview:1.0.1'

首先在需要使用的页面

//MainActivity调用的页面,urls传入的图片数据,pos传入的图片位置,view需要共享的view
ImagePagerActivity.startImagePage(MainActivity.this,
                        urls,pos,view);

其次设置转场动画的共享元素,因为跳转和返回时都会调用onMapSharedElements,需要判断bundle是否为空,bundle会在返回的时候在onActivityReenter获取

    //设置转场动画的共享元素,因为跳转和返回时都会调用onMapSharedElements,需要判断bundle是否为空
    setExitSharedElementCallback(new SharedElementCallback() {
        @Override
        public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {
            if (bundle!=null){
                int index = bundle.getInt(ImagePagerActivity.STATE_POSITION,0);
                sharedElements.clear();
                sharedElements.put("img", recyclerView.getLayoutManager().findViewByPosition(index));
                bundle=null;
            }
        }
    });

在返回的时候获取数据bundle

@Override
public void onActivityReenter(int resultCode, Intent data) {
    super.onActivityReenter(resultCode, data);
    bundle = data.getExtras();
    int currentPosition = bundle.getInt(ImagePagerActivity.STATE_POSITION,0);
    //做相应的滚动
    recyclerView.scrollToPosition(currentPosition);
    //暂时延迟 Transition 的使用,直到我们确定了共享元素的确切大小和位置才使用
    //postponeEnterTransition后不要忘记调用startPostponedEnterTransition
    ActivityCompat.postponeEnterTransition(this);
    recyclerView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            recyclerView.getViewTreeObserver().removeOnPreDrawListener(this);
            // TODO: figure out why it is necessary to request layout here in order to get a smooth transition.
            recyclerView.requestLayout();
            //共享元素准备好后调用startPostponedEnterTransition来恢复过渡效果
            ActivityCompat.startPostponedEnterTransition(MainActivity.this);
            return true;
        }
    });
}

imagereview's People

Contributors

johnsonhou avatar

Stargazers

 avatar  avatar  avatar o is null avatar Naturally Of Live  avatar  avatar  avatar  avatar  avatar Fankesyooni avatar  avatar  avatar  avatar 杨国亮 avatar  avatar  avatar zyh avatar  avatar theshdf avatar  avatar  avatar shdfzcm avatar Blue avatar  avatar  avatar  avatar  avatar keze avatar nextdiscover avatar YingKe avatar zuoni avatar Orange avatar  avatar  avatar 呆马 avatar AHuier avatar Blazer avatar xupingwei avatar 胜 avatar  avatar m122469119 avatar monkey1992 avatar  avatar HaoKing avatar  avatar 一笑轮回 avatar Nisarg avatar Pranav Lathigara avatar  avatar Peelson avatar  avatar  avatar ᠵᠠᠭᠠᠨᠵᠠᠪ ᠪᠤᠷᠵᠢᠭᠤᠳ ᠰᠠᠴᠤᠷᠠᠭ avatar  avatar feng_gao avatar DowneyHsu avatar  avatar Jary avatar Crazy avatar  avatar 你需要一台永动机 avatar  avatar  avatar  avatar

Watchers

James Cloos avatar  avatar

imagereview's Issues

图片不缩小关闭

点击一张图片进入详情页先往左划一张再往右划一张后第二次滑动的这张图片下滑的时候不会缩小

You need to use a Theme.AppCompat theme

11-15 14:45:52.277 5080-5080/com.chnsys.szyfy E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.chnsys.szyfy, PID: 5080
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.chnsys.szyfy/com.jchou.imagereview.ui.ImagePagerActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3194)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3302)
at android.app.ActivityThread.-wrap12(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1891)
at android.os.Handler.dispatchMessage(Handler.java:108)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7425)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:354)
at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:323)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:284)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.jchou.imagereview.ui.ImagePagerActivity.onCreate(ImagePagerActivity.java:73)
at android.app.Activity.performCreate(Activity.java:7372)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1218)

代码:
ImagePagerActivity.startImagePage(AlbumSelectActivity.this, urlList, pos, gridView.getChildAt(pos));

我的项目设置为没有主题NoTitle,运行报错!楼主帮我看看什么原因?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.