Search in sources :

Example 1 with MaterialItemView

use of me.majiajie.pagerbottomtabstrip.item.MaterialItemView in project PagerBottomTabStrip by tyzlmjj.

the class MaterialItemLayout method initialize.

/**
     * 初始化方法
     *
     * @param items 按钮集合
     * @param mode  {@link MaterialMode}
     */
public void initialize(List<MaterialItemView> items, int mode) {
    mItems = items;
    //判断是否需要切换背景
    if ((mode & MaterialMode.CHANGE_BACKGROUND_COLOR) > 0) {
        //初始化一些成员变量
        mChangeBackgroundMode = true;
        mOvals = new ArrayList<>();
        mColors = new ArrayList<>();
        mInterpolator = new AccelerateDecelerateInterpolator();
        mTempRectF = new RectF();
        mPaint = new Paint();
        //获取各项的选中颜色,并替换成白色
        for (MaterialItemView v : mItems) {
            mColors.add(v.getCheckedColor());
            v.setCheckedColor(Color.WHITE);
        }
        //设置默认的背景
        setBackgroundColor(mColors.get(DEFAULT_SELECTED));
    } else {
        //设置按钮点击效果
        for (MaterialItemView v : mItems) {
            v.setBackgroundResource(R.drawable.material_item_background);
        }
    }
    //判断是否隐藏文字
    if ((mode & MaterialMode.HIDE_TEXT) > 0) {
        mShiftingMode = true;
        for (MaterialItemView v : mItems) {
            v.setShiftingMode(true);
        }
    }
    //添加按钮到布局,并注册点击事件
    int n = mItems.size();
    for (int i = 0; i < n; i++) {
        MaterialItemView v = mItems.get(i);
        v.setChecked(false);
        this.addView(v);
        final int finali = i;
        v.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                setSelect(finali, mLastUpX, mLastUpY);
            }
        });
    }
    //默认选中第一项
    mSelected = DEFAULT_SELECTED;
    mItems.get(DEFAULT_SELECTED).setChecked(true);
}
Also used : RectF(android.graphics.RectF) MaterialItemView(me.majiajie.pagerbottomtabstrip.item.MaterialItemView) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) Paint(android.graphics.Paint) MaterialItemView(me.majiajie.pagerbottomtabstrip.item.MaterialItemView) View(android.view.View) Paint(android.graphics.Paint)

Aggregations

Paint (android.graphics.Paint)1 RectF (android.graphics.RectF)1 View (android.view.View)1 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)1 MaterialItemView (me.majiajie.pagerbottomtabstrip.item.MaterialItemView)1