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

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

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

效果图:


示例代码:

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();
    }


猜你喜欢

转载自blog.csdn.net/razor1991/article/details/45054585