Skip to content

Commit

Permalink
1.fixBug:图片与标题对不上的问题
Browse files Browse the repository at this point in the history
2.fixBug:刷新页面时,小圆点会不断增加
  • Loading branch information
caikaidev committed Oct 31, 2016
1 parent 42f055b commit 6d472c8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public void setAdapter(BaseViewPagerAdapter adapter) {

public void initPointView(int size) {

layout.removeAllViews();
for (int i = 0; i < size; i++) {
ImageView imageView = new ImageView(mContext);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(20, 20);
Expand Down Expand Up @@ -138,4 +139,16 @@ public void onDestroy() {
}
}

public void onResume(){
if (mViewPager != null && !mViewPager.isStart()) {
mViewPager.start();
}
}

public void onPause(){
if (mViewPager != null) {
mViewPager.onStop();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public class AutoViewPager extends ViewPager {

private Timer mTimer;
private AutoTask mTask;
private boolean isStart;

public boolean isStart() {
return isStart;
}

public AutoViewPager(Context context) {
super(context);
Expand All @@ -37,9 +42,14 @@ public void init(AutoViewPager viewPager,BaseViewPagerAdapter adapter){
}

public void start(){

if (((BaseViewPagerAdapter)getAdapter()).getRealCount() == 0) {
return;
}
//先停止
onStop();

isStart = true;
if (mTimer == null) {
mTimer = new Timer();
}
Expand Down Expand Up @@ -98,6 +108,8 @@ public void onStop(){
mTimer.cancel();
mTimer = null;
}

isStart = false;
}

public void onDestroy(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ public void init(AutoViewPager viewPager,BaseViewPagerAdapter adapter){
int position = Integer.MAX_VALUE/2 - (Integer.MAX_VALUE/2) % getRealCount();
mView.setCurrentItem(position);

mView.start();
mView.updatePointView(getRealCount());
if (!mView.isStart()) {
mView.start();
mView.updatePointView(getRealCount());
}

}

public void setListener(OnAutoViewPagerItemClickListener listener) {
Expand Down Expand Up @@ -102,8 +105,11 @@ public void init(List<T> list){

notifyDataSetChanged();

mView.start();
mView.updatePointView(getRealCount());
if (!mView.isStart()) {
mView.start();
mView.updatePointView(getRealCount());
}


}

Expand All @@ -125,6 +131,19 @@ public void destroyItem(ViewGroup container, int position, Object object) {
public Object instantiateItem(ViewGroup container, final int position) {
ImageView view = (ImageView) LayoutInflater.from(mContext)
.inflate(R.layout.imageview,container,false);
loadImage(view,position, data.get(position % getRealCount()));
container.addView(view);

//设置标题(不知道为什么标题跟图片对不上,所以做了如下处理,有大神看到帮忙看看。。。)
if (mView.getSubTitle() != null){
if (position == 0){
setSubTitle(mView.getSubTitle(),position,data.get((getRealCount() - 1)));
}else {
setSubTitle(mView.getSubTitle(),position,data.get((position - 1) % getRealCount()));
}

}

view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand All @@ -134,16 +153,6 @@ public void onClick(View view) {
}
});

loadImage(view,position, data.get(position % getRealCount()));
container.addView(view);

//设置标题
if (mView.getSubTitle() != null){
setSubTitle(mView.getSubTitle(),position,data.get(position % getRealCount()));
}else {

}

return view;
}

Expand Down

0 comments on commit 6d472c8

Please sign in to comment.