美文网首页
长图加载(Pop+Glide+ScrollView)

长图加载(Pop+Glide+ScrollView)

作者: 小赵不在 | 来源:发表于2020-12-17 09:57 被阅读0次

    1. 点击控件弹出pop

    R.id.tv_detial -> showPop()
    

    2. showPop方法(长图用Glide加载)

     private fun showPop() {
            val view = LayoutInflater.from(context).inflate(R.layout.pop_kid, null)
            var iv_scrollView = view.findViewById<ImageView>(R.id.iv_scrollView)
            Glide.with(this)
                .load("http://hyt.edudjt.com/hyt/LessonIntroduce/kid_immature.png")
                .error(R.mipmap.dog_step1)
                .into(iv_scrollView)
            val popupWindow = PopupWindow(
                view,
                ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT
            )
            popupWindow.setBackgroundDrawable(ColorDrawable())
            popupWindow.isOutsideTouchable = true
            setBackGroundAlpha(0.5f)
            popupWindow.isFocusable = true
            popupWindow.setOnDismissListener {
                setBackGroundAlpha(1f)
            }
            popupWindow.showAtLocation(cl, Gravity.RIGHT, 0, 0)
        }
    
        private fun setBackGroundAlpha(bgAlpha: Float) {
            val lp = (context as Activity).window.attributes
            lp.alpha = bgAlpha
            (context as Activity).window.attributes = lp
        }
    
    

    3. Pop布局(不能用约束布局)

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <ScrollView
            android:id="@+id/scrollView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fadingEdge="vertical"
            android:scrollbars="none">
    
                <ImageView
                    android:id="@+id/iv_scrollView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                     />
    
        </ScrollView>
    </LinearLayout>
    

    相关文章

      网友评论

          本文标题:长图加载(Pop+Glide+ScrollView)

          本文链接:https://www.haomeiwen.com/subject/dgxbgktx.html