Skip to content

Commit 63fa38c

Browse files
committed
0.41版本,增加了更换指示器样式的方法
1 parent 98c4b50 commit 63fa38c

File tree

2 files changed

+58
-11
lines changed

2 files changed

+58
-11
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,17 @@ PhotoViewer
8585

8686
## Feature
8787

88-
- ~~增加弹出动画~~(完成)
89-
- 增加加载图片时候的loading
90-
- ~~点击退出时的动画(目前只有滑动退出时有动画效果)~~(完成)
88+
- 加载大图时没有动画的问题
9189

9290

9391
## 更新日志
9492

93+
### 0.41
94+
95+
增加了指示器样式的选择,`setIndicatorType(PhotoViewer.INDICATOR_TYPE_DOT/INDICATOR_TYPE_TEXT)`
96+
97+
但是如果图片>9张,则默认显示文字样式,因为屏幕装不下
98+
9599
### 0.40
96100

97101
增加了长按监听接口

photoviewer/src/main/java/com/wanglu/photoviewerlibrary/PhotoViewer.kt

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.wanglu.photoviewerlibrary
33
import android.animation.LayoutTransition
44
import android.animation.ObjectAnimator
55
import android.annotation.SuppressLint
6+
import android.graphics.Color
67
import android.os.Bundle
78
import android.support.v4.app.Fragment
89
import android.support.v4.view.ViewPager
@@ -14,10 +15,7 @@ import android.view.Gravity
1415
import android.view.LayoutInflater
1516
import android.view.View
1617
import 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.*
2119
import java.lang.ref.WeakReference
2220
import java.util.*
2321
import kotlin.concurrent.timerTask
@@ -28,6 +26,11 @@ import kotlin.concurrent.timerTask
2826
* Created by WangLu on 2018/7/15.
2927
*/
3028
object 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

Comments
 (0)