Skip to content

Commit cf913d2

Browse files
committed
添加图片序号显示位置设置
1 parent c8074d0 commit cf913d2

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

app/src/main/java/com/liyi/example/PicActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public void onItemClick(int i, View view) {
6565
imageViewer = ImageViewer.newInstance();
6666
}
6767
imageViewer.setLocations(mRects)
68+
.setIndexGravity(ImageViewer.BOTTOM)
6869
.setResources(i, mList, PicActivity.this)
6970
.show(getSupportFragmentManager(), "pic");
7071
}

image-viewer/src/main/java/com/liyi/viewer/ImageViewer.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import android.support.v4.app.DialogFragment;
1515
import android.support.v4.view.ViewPager;
1616
import android.util.DisplayMetrics;
17+
import android.view.Gravity;
1718
import android.view.KeyEvent;
1819
import android.view.LayoutInflater;
1920
import android.view.View;
@@ -33,6 +34,9 @@
3334
* A control for viewing images
3435
*/
3536
public class ImageViewer extends DialogFragment implements DialogInterface.OnKeyListener {
37+
public static final int TOP = 0;
38+
public static final int BOTTOM = 1;
39+
3640
private View contentView;
3741
private View v_bg;
3842
private PhotoView photoVi_current;
@@ -44,6 +48,7 @@ public class ImageViewer extends DialogFragment implements DialogInterface.OnKey
4448
private List<View> mViews;
4549
private ViewGroup.LayoutParams mCurrentParams;
4650

51+
private int mIndexGravity = TOP;
4752
// The location of the image on the screen
4853
private List<Rect> mLocations;
4954
// The sequence number of the first picture shown
@@ -84,6 +89,14 @@ private void initUI() {
8489
mAdapter.setData(mViews);
8590
viewpager.setAdapter(mAdapter);
8691
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+
}
87100
}
88101
}
89102

@@ -239,6 +252,17 @@ public void onPhotoTap(View view, float x, float y) {
239252
return this;
240253
}
241254

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+
242266
/**
243267
* Zoom in to full-screen animation
244268
*/
@@ -283,7 +307,6 @@ public void onAnimationUpdate(ValueAnimator animation) {
283307
if (fraction == 1) {
284308
if (mViews.size() > 1) {
285309
tv_index.setVisibility(View.VISIBLE);
286-
tv_index.setText((mBeginIndex + 1) + "/" + mViews.size());
287310
} else {
288311
tv_index.setVisibility(View.GONE);
289312
}

image-viewer/src/main/res/layout/dlgfmt_image_viewer.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
android:layout_width="wrap_content"
2121
android:layout_height="wrap_content"
2222
android:layout_gravity="top|center_horizontal"
23+
android:layout_marginBottom="10dp"
2324
android:layout_marginTop="10dp"
2425
android:textColor="@color/white"
2526
android:textSize="18sp"

0 commit comments

Comments
 (0)