Giter VIP home page Giter VIP logo

showimagesdialogdemo's Introduction

ShowImagesDialogDemo

PhotoView+Glide+Dialog+ViewPager:打造轻量级的图片浏览方案 其实不单单是做简单的图片浏览、android原生的dialog可以做到activity、fragment的大部分展示功能,而且更轻量化,易于封装与维护。

几点需要注意的地方

由于是PhotoView嵌套了Viewpager,滑动时有一定几率崩溃,github上已经给出了对应的解决方案:继承一个viewpager,在相关方法里try catch 异常。

 * 为了解决photoview嵌套在部分父控件时闪退的bug,github上提供的解决方案
 */
public class ShowImagesViewPager extends ViewPager {
    
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        try {
            return super.onInterceptTouchEvent(ev);
        } catch (IllegalArgumentException e) {
            //uncomment if you really want to see these errors
            //e.printStackTrace();
            return false;
        }
    }
}

为了使dialog具有全屏透明效果,需要给我们的dialog一个新的style。

    <style name="transparentBgDialog" parent="@android:style/Theme.Dialog">
        <item name="android:windowFrame">@null</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@color/transparent</item>
        <item name="android:backgroundDimEnabled">true</item>
        <item name="android:background">@color/transparent</item>
        <item name="android:windowNoTitle">true</item>
    </style>

所以,马上替换吧!

dialog正常显示photoview

dialog正常显示photoview

同一张图片缩放后的photoview

同一张图片缩放后的photoview

图片

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.