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

来源:互联网 发布:java 异常 编辑:程序博客网 时间:2024/06/04 19:29

找到方法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();    }


0 0
原创粉丝点击