Skip to content

Commit

Permalink
修复bug
Browse files Browse the repository at this point in the history
  • Loading branch information
wanglu1209 committed Oct 22, 2016
1 parent 201de21 commit 5c36898
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ protected void onCreate(Bundle savedInstanceState) {
* 最后需要调用开始轮播
* 个人建议在onPause()/onDestroy()方法中来停止 -- stopAutoPlay()
*/
banner.setDot(R.drawable.no_selected_dot, R.drawable.selected_dot).
setDotGravity(Banner.CENTER).
setAdapter(ad).
setOnItemClickListener(new BannerPagerAdapter.onItemClickListener() {
@Override
public void onClick(int position) {
Toast.makeText(MainActivity.this, "" + position, Toast.LENGTH_SHORT).show();
}
}).
startAutoPlay();
banner.setDotGravity(Banner.CENTER).
setDot(R.drawable.no_selected_dot, R.drawable.selected_dot).
setAdapter(ad).
setOnItemClickListener(new BannerPagerAdapter.onItemClickListener() {
@Override
public void onClick(int position) {
Toast.makeText(MainActivity.this, "" + position, Toast.LENGTH_SHORT).show();
}
}).
startAutoPlay();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,45 @@ public Banner setAdapter(BannerPagerAdapter adapter) {
mPager.setAdapter(mAdapter);
mPager.setCurrentItem(mAdapter.size);


LinearLayout.LayoutParams dotParams =
new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
/**
* 未选中小圆点的间距
*/
dotParams.rightMargin = 12;

/**
* 创建未选中的小圆点
*/
for (int i = 0; i < mAdapter.size; i++) {
ImageView iv = new ImageView(mContext);
iv.setImageDrawable(mContext.getResources().getDrawable(mDot[0]));
iv.setLayoutParams(dotParams);
mDotGroup.addView(iv);
}


/**
* 添加到任务栈,当前所有任务完事之后添加已经选中的那个小圆点
*/
post(new Runnable() {
@Override
public void run() {

ImageView iv = new ImageView(mContext);
iv.setImageDrawable(mContext.getResources().getDrawable(mDot[1]));
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
/**
* 设置选中小圆点的左边距
*/
params.leftMargin = (int) mDotGroup.getChildAt(0).getX();
params.gravity = Gravity.BOTTOM;
mFrameLayout.addView(iv, params);
mSelectedDot = mFrameLayout.getChildAt(1);
}
});
return this;
}

Expand All @@ -157,42 +196,7 @@ public Banner setTime(int time) {
public Banner setDot(int... dots) {
mDot[0] = dots[0];
mDot[1] = dots[1];
/**
* 添加到任务栈,当前所有任务完事之后添加已经选中的那个小圆点
*/
post(new Runnable() {
@Override
public void run() {

LinearLayout.LayoutParams dotParams =
new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
/**
* 未选中小圆点的间距
*/
dotParams.rightMargin = 12;
/**
* 创建未选中的小圆点
*/
for (int i = 0; i < mAdapter.size; i++) {
ImageView iv = new ImageView(mContext);
iv.setImageDrawable(mContext.getResources().getDrawable(mDot[0]));
iv.setLayoutParams(dotParams);
mDotGroup.addView(iv);
}

ImageView iv = new ImageView(mContext);
iv.setImageDrawable(mContext.getResources().getDrawable(mDot[1]));
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
/**
* 设置选中小圆点的左边距
*/
params.leftMargin = (int) mDotGroup.getChildAt(0).getX();
params.gravity = Gravity.BOTTOM;
mFrameLayout.addView(iv, params);
mSelectedDot = mFrameLayout.getChildAt(1);
}
});
return this;
}

Expand Down

0 comments on commit 5c36898

Please sign in to comment.