14
14
import android .support .v4 .app .DialogFragment ;
15
15
import android .support .v4 .view .ViewPager ;
16
16
import android .util .DisplayMetrics ;
17
+ import android .view .Gravity ;
17
18
import android .view .KeyEvent ;
18
19
import android .view .LayoutInflater ;
19
20
import android .view .View ;
33
34
* A control for viewing images
34
35
*/
35
36
public class ImageViewer extends DialogFragment implements DialogInterface .OnKeyListener {
37
+ public static final int TOP = 0 ;
38
+ public static final int BOTTOM = 1 ;
39
+
36
40
private View contentView ;
37
41
private View v_bg ;
38
42
private PhotoView photoVi_current ;
@@ -44,6 +48,7 @@ public class ImageViewer extends DialogFragment implements DialogInterface.OnKey
44
48
private List <View > mViews ;
45
49
private ViewGroup .LayoutParams mCurrentParams ;
46
50
51
+ private int mIndexGravity = TOP ;
47
52
// The location of the image on the screen
48
53
private List <Rect > mLocations ;
49
54
// The sequence number of the first picture shown
@@ -84,6 +89,14 @@ private void initUI() {
84
89
mAdapter .setData (mViews );
85
90
viewpager .setAdapter (mAdapter );
86
91
viewpager .setCurrentItem (mBeginIndex );
92
+ if (mViews .size () > 1 ) {
93
+ tv_index .setText ((mBeginIndex + 1 ) + "/" + mViews .size ());
94
+ if (mIndexGravity == BOTTOM ) {
95
+ tv_index .setGravity (Gravity .BOTTOM );
96
+ }
97
+ } else {
98
+ tv_index .setVisibility (View .GONE );
99
+ }
87
100
}
88
101
}
89
102
@@ -239,6 +252,17 @@ public void onPhotoTap(View view, float x, float y) {
239
252
return this ;
240
253
}
241
254
255
+ /**
256
+ * Set the location of the image serial number
257
+ *
258
+ * @param gravity
259
+ * @return
260
+ */
261
+ public ImageViewer setIndexGravity (int gravity ) {
262
+ mIndexGravity = gravity ;
263
+ return this ;
264
+ }
265
+
242
266
/**
243
267
* Zoom in to full-screen animation
244
268
*/
@@ -283,7 +307,6 @@ public void onAnimationUpdate(ValueAnimator animation) {
283
307
if (fraction == 1 ) {
284
308
if (mViews .size () > 1 ) {
285
309
tv_index .setVisibility (View .VISIBLE );
286
- tv_index .setText ((mBeginIndex + 1 ) + "/" + mViews .size ());
287
310
} else {
288
311
tv_index .setVisibility (View .GONE );
289
312
}
0 commit comments