设置ViewPagerIndicator框架中IconPageIndicator的图片指示器间距

找到方法void com.viewpagerindicator.IconPageIndicator.notifyDataSetChanged();

必须使用LinearLayout.LayoutParams来设置ImageView的属性,否则无效

效果图:

设置ViewPagerIndicator框架中IconPageIndicator的图片指示器间距_第1张图片

示例代码:

public void notifyDataSetChanged() {
        mIconsLayout.removeAllViews();
        IconPagerAdapter iconAdapter = (IconPagerAdapter) mViewPager.getAdapter();
        int count = iconAdapter.getCount();
        
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        lp.leftMargin=4;
        lp.rightMargin=4;
        for (int i = 0; i < count; i++) {
            ImageView view = new ImageView(getContext(), null, R.attr.vpiIconPageIndicatorStyle);
            view.setImageResource(iconAdapter.getIconResId(i));
            view.setLayoutParams(lp);
            mIconsLayout.addView(view);
        }
        if (mSelectedIndex > count) {
            mSelectedIndex = count - 1;
        }
        setCurrentItem(mSelectedIndex);
        requestLayout();
    }


你可能感兴趣的:(设置ViewPagerIndicator框架中IconPageIndicator的图片指示器间距)