@@ -3,6 +3,7 @@ package com.wanglu.photoviewerlibrary
33import android.animation.LayoutTransition
44import android.animation.ObjectAnimator
55import android.annotation.SuppressLint
6+ import android.graphics.Color
67import android.os.Bundle
78import android.support.v4.app.Fragment
89import android.support.v4.view.ViewPager
@@ -14,10 +15,7 @@ import android.view.Gravity
1415import android.view.LayoutInflater
1516import android.view.View
1617import android.view.ViewGroup
17- import android.widget.AbsListView
18- import android.widget.FrameLayout
19- import android.widget.ImageView
20- import android.widget.LinearLayout
18+ import android.widget.*
2119import java.lang.ref.WeakReference
2220import java.util.*
2321import kotlin.concurrent.timerTask
@@ -28,6 +26,11 @@ import kotlin.concurrent.timerTask
2826 * Created by WangLu on 2018/7/15.
2927 */
3028object PhotoViewer {
29+
30+ const val INDICATOR_TYPE_DOT = " INDICATOR_TYPE_DOT"
31+ const val INDICATOR_TYPE_TEXT = " INDICATOR_TYPE_TEXT"
32+
33+
3134 internal var mInterface: ShowImageViewInterface ? = null
3235
3336 private lateinit var imgData: ArrayList <String > // 图片数据
@@ -37,6 +40,11 @@ object PhotoViewer {
3740 private var clickView: WeakReference <View >? = null // 点击那一张图片时候的view
3841 private var longClickListener: OnLongClickListener ? = null
3942
43+ private var indicatorType = INDICATOR_TYPE_DOT // 默认type为小圆点
44+
45+
46+
47+
4048 /* *
4149 * 小圆点的drawable
4250 * 下标0的为没有被选中的
@@ -150,6 +158,15 @@ object PhotoViewer {
150158 return this
151159 }
152160
161+
162+ /* *
163+ * 设置指示器的样式,但是如果图片大于9张,则默认设置为文字样式
164+ */
165+ fun setIndicatorType (type : String ): PhotoViewer {
166+ this .indicatorType = type
167+ return this
168+ }
169+
153170 private fun show (activity : AppCompatActivity ) {
154171
155172
@@ -176,6 +193,7 @@ object PhotoViewer {
176193
177194 /* *
178195 * 存放没有被选中的小圆点Group和已经被选中小圆点
196+ * 或者存放数字
179197 */
180198 var mFrameLayout: FrameLayout ? = null
181199 /* *
@@ -184,6 +202,12 @@ object PhotoViewer {
184202 var mSelectedDot: View ? = null
185203
186204
205+ /* *
206+ * 文字版本当前页
207+ */
208+ var tv: TextView ? = null
209+
210+
187211
188212 for (i in 0 until imgData.size) {
189213 val f = PhotoViewerFragment ()
@@ -248,6 +272,13 @@ object PhotoViewer {
248272 }
249273 }
250274
275+ /* *
276+ * 设置文字版本当前页的值
277+ */
278+ if (tv != null ){
279+ tv!! .text = " ${currentPage + 1 } /${imgData.size} "
280+ }
281+
251282 // 这里延时0.2s是为了解决上面👆的问题。因为如果刚调用ScrollToPosition方法,就获取itemView是获取不到的,所以要延时一下
252283 Timer ().schedule(timerTask {
253284 val b = Bundle ()
@@ -265,8 +296,9 @@ object PhotoViewer {
265296 frameLayout.addView(photoViewLayout)
266297
267298
268- if (imgData.size > 1 )
269- frameLayout.post {
299+ frameLayout.post {
300+ mFrameLayout = FrameLayout (activity)
301+ if (imgData.size in 2 .. 9 && indicatorType == INDICATOR_TYPE_DOT ) {
270302
271303 /* *
272304 * 实例化两个Group
@@ -275,7 +307,6 @@ object PhotoViewer {
275307 mFrameLayout!! .removeAllViews()
276308 mFrameLayout = null
277309 }
278- mFrameLayout = FrameLayout (activity)
279310 if (mDotGroup != null ) {
280311 mDotGroup!! .removeAllViews()
281312 mDotGroup = null
@@ -344,11 +375,23 @@ object PhotoViewer {
344375 */
345376 frameLayout.addView(mFrameLayout, params)
346377 }
378+ } else {
379+ tv = TextView (activity)
380+ tv!! .text = " ${currentPage + 1 } /${imgData.size} "
381+ tv!! .setTextColor(Color .WHITE )
382+ tv!! .gravity = Gravity .CENTER_HORIZONTAL or Gravity .BOTTOM
383+ tv!! .textSize = 18f
384+ mFrameLayout!! .addView(tv)
385+ val params = LinearLayout .LayoutParams (ViewGroup .LayoutParams .MATCH_PARENT ,
386+ ViewGroup .LayoutParams .MATCH_PARENT )
387+ params.bottomMargin = Utils .dp2px(activity, 80 )
388+ frameLayout.addView(mFrameLayout, params)
389+
347390 }
391+ }
348392 decorView.addView(frameLayout, ViewGroup .LayoutParams .MATCH_PARENT , ViewGroup .LayoutParams .MATCH_PARENT )
349393
350394 }
351395
352396
353-
354397}
0 commit comments