Search in sources :

Example 51 with LayoutParams

use of android.support.v7.widget.RecyclerView.LayoutParams in project RecyclerBanner by renjianan.

the class BannerLayout method initView.

protected void initView(Context context, AttributeSet attrs) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BannerLayout);
    showIndicator = a.getBoolean(R.styleable.BannerLayout_showIndicator, true);
    autoPlayDuration = a.getInt(R.styleable.BannerLayout_interval, 4000);
    isAutoPlaying = a.getBoolean(R.styleable.BannerLayout_autoPlaying, true);
    itemSpace = a.getInt(R.styleable.BannerLayout_itemSpace, 20);
    centerScale = a.getFloat(R.styleable.BannerLayout_centerScale, 1.2f);
    moveSpeed = a.getFloat(R.styleable.BannerLayout_moveSpeed, 1.0f);
    if (mSelectedDrawable == null) {
        // 绘制默认选中状态图形
        GradientDrawable selectedGradientDrawable = new GradientDrawable();
        selectedGradientDrawable.setShape(GradientDrawable.OVAL);
        selectedGradientDrawable.setColor(Color.RED);
        selectedGradientDrawable.setSize(dp2px(5), dp2px(5));
        selectedGradientDrawable.setCornerRadius(dp2px(5) / 2);
        mSelectedDrawable = new LayerDrawable(new Drawable[] { selectedGradientDrawable });
    }
    if (mUnselectedDrawable == null) {
        // 绘制默认未选中状态图形
        GradientDrawable unSelectedGradientDrawable = new GradientDrawable();
        unSelectedGradientDrawable.setShape(GradientDrawable.OVAL);
        unSelectedGradientDrawable.setColor(Color.GRAY);
        unSelectedGradientDrawable.setSize(dp2px(5), dp2px(5));
        unSelectedGradientDrawable.setCornerRadius(dp2px(5) / 2);
        mUnselectedDrawable = new LayerDrawable(new Drawable[] { unSelectedGradientDrawable });
    }
    indicatorMargin = dp2px(4);
    int marginLeft = dp2px(16);
    int marginRight = dp2px(0);
    int marginBottom = dp2px(11);
    int gravity = GravityCompat.START;
    int o = a.getInt(R.styleable.BannerLayout_orientation, 0);
    int orientation = 0;
    if (o == 0) {
        orientation = OrientationHelper.HORIZONTAL;
    } else if (o == 1) {
        orientation = OrientationHelper.VERTICAL;
    }
    a.recycle();
    // 轮播图部分
    mRecyclerView = new RecyclerView(context);
    LayoutParams vpLayoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    addView(mRecyclerView, vpLayoutParams);
    mLayoutManager = new BannerLayoutManager(getContext(), orientation);
    mLayoutManager.setItemSpace(itemSpace);
    mLayoutManager.setCenterScale(centerScale);
    mLayoutManager.setMoveSpeed(moveSpeed);
    mRecyclerView.setLayoutManager(mLayoutManager);
    new CenterSnapHelper().attachToRecyclerView(mRecyclerView);
    // 指示器部分
    indicatorContainer = new RecyclerView(context);
    LinearLayoutManager indicatorLayoutManager = new LinearLayoutManager(context, orientation, false);
    indicatorContainer.setLayoutManager(indicatorLayoutManager);
    indicatorAdapter = new IndicatorAdapter();
    indicatorContainer.setAdapter(indicatorAdapter);
    LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.BOTTOM | gravity;
    params.setMargins(marginLeft, 0, marginRight, marginBottom);
    addView(indicatorContainer, params);
    if (!showIndicator) {
        indicatorContainer.setVisibility(GONE);
    }
}
Also used : CenterSnapHelper(com.example.library.banner.layoutmanager.CenterSnapHelper) TypedArray(android.content.res.TypedArray) LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) Drawable(android.graphics.drawable.Drawable) GradientDrawable(android.graphics.drawable.GradientDrawable) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) BannerLayoutManager(com.example.library.banner.layoutmanager.BannerLayoutManager) GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 52 with LayoutParams

use of android.support.v7.widget.RecyclerView.LayoutParams in project RecyclerBanner by renjianan.

the class RecyclerViewBannerBase method initView.

protected void initView(Context context, AttributeSet attrs) {
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RecyclerViewBannerBase);
    showIndicator = a.getBoolean(R.styleable.RecyclerViewBannerBase_showIndicator, true);
    autoPlayDuration = a.getInt(R.styleable.RecyclerViewBannerBase_interval, 4000);
    isAutoPlaying = a.getBoolean(R.styleable.RecyclerViewBannerBase_autoPlaying, true);
    mSelectedDrawable = a.getDrawable(R.styleable.RecyclerViewBannerBase_indicatorSelectedSrc);
    mUnselectedDrawable = a.getDrawable(R.styleable.RecyclerViewBannerBase_indicatorUnselectedSrc);
    if (mSelectedDrawable == null) {
        // 绘制默认选中状态图形
        GradientDrawable selectedGradientDrawable = new GradientDrawable();
        selectedGradientDrawable.setShape(GradientDrawable.OVAL);
        selectedGradientDrawable.setColor(Color.RED);
        selectedGradientDrawable.setSize(dp2px(5), dp2px(5));
        selectedGradientDrawable.setCornerRadius(dp2px(5) / 2);
        mSelectedDrawable = new LayerDrawable(new Drawable[] { selectedGradientDrawable });
    }
    if (mUnselectedDrawable == null) {
        // 绘制默认未选中状态图形
        GradientDrawable unSelectedGradientDrawable = new GradientDrawable();
        unSelectedGradientDrawable.setShape(GradientDrawable.OVAL);
        unSelectedGradientDrawable.setColor(Color.GRAY);
        unSelectedGradientDrawable.setSize(dp2px(5), dp2px(5));
        unSelectedGradientDrawable.setCornerRadius(dp2px(5) / 2);
        mUnselectedDrawable = new LayerDrawable(new Drawable[] { unSelectedGradientDrawable });
    }
    indicatorMargin = a.getDimensionPixelSize(R.styleable.RecyclerViewBannerBase_indicatorSpace, dp2px(4));
    int marginLeft = a.getDimensionPixelSize(R.styleable.RecyclerViewBannerBase_indicatorMarginLeft, dp2px(16));
    int marginRight = a.getDimensionPixelSize(R.styleable.RecyclerViewBannerBase_indicatorMarginRight, dp2px(0));
    int marginBottom = a.getDimensionPixelSize(R.styleable.RecyclerViewBannerBase_indicatorMarginBottom, dp2px(11));
    int g = a.getInt(R.styleable.RecyclerViewBannerBase_indicatorGravity, 0);
    int gravity;
    if (g == 0) {
        gravity = GravityCompat.START;
    } else if (g == 2) {
        gravity = GravityCompat.END;
    } else {
        gravity = Gravity.CENTER;
    }
    int o = a.getInt(R.styleable.RecyclerViewBannerBase_orientation, 0);
    int orientation = 0;
    if (o == 0) {
        orientation = LinearLayoutManager.HORIZONTAL;
    } else if (o == 1) {
        orientation = LinearLayoutManager.VERTICAL;
    }
    a.recycle();
    // recyclerView部分
    mRecyclerView = new RecyclerView(context);
    new PagerSnapHelper().attachToRecyclerView(mRecyclerView);
    mLayoutManager = getLayoutManager(context, orientation);
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            onBannerScrolled(recyclerView, dx, dy);
        }

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            onBannerScrollStateChanged(recyclerView, newState);
        }
    });
    LayoutParams vpLayoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    addView(mRecyclerView, vpLayoutParams);
    // 指示器部分
    indicatorContainer = new RecyclerView(context);
    LinearLayoutManager indicatorLayoutManager = new LinearLayoutManager(context, orientation, false);
    indicatorContainer.setLayoutManager(indicatorLayoutManager);
    indicatorAdapter = new IndicatorAdapter();
    indicatorContainer.setAdapter(indicatorAdapter);
    LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.BOTTOM | gravity;
    params.setMargins(marginLeft, 0, marginRight, marginBottom);
    addView(indicatorContainer, params);
    if (!showIndicator) {
        indicatorContainer.setVisibility(GONE);
    }
}
Also used : TypedArray(android.content.res.TypedArray) LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) Drawable(android.graphics.drawable.Drawable) GradientDrawable(android.graphics.drawable.GradientDrawable) PagerSnapHelper(android.support.v7.widget.PagerSnapHelper) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) GradientDrawable(android.graphics.drawable.GradientDrawable)

Example 53 with LayoutParams

use of android.support.v7.widget.RecyclerView.LayoutParams in project FastDev4Android by jiangqqlmj.

the class AdvanceDecoration method drawVDeraction.

/**
     * 绘制垂直方向的分割线
     * @param c
     * @param parent
     */
private void drawVDeraction(Canvas c, RecyclerView parent) {
    int top = parent.getPaddingTop();
    int bottom = parent.getHeight() - parent.getPaddingBottom();
    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = parent.getChildAt(i);
        RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams();
        int left = child.getRight() + layoutParams.rightMargin;
        int right = left + mDivider.getIntrinsicWidth();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 54 with LayoutParams

use of android.support.v7.widget.RecyclerView.LayoutParams in project FastDev4Android by jiangqqlmj.

the class TestDecoration method onDraw.

/**
     * 进行自定义绘制
     * @param c
     * @param parent
     * @param state
     */
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    int top = parent.getPaddingTop();
    int bottom = parent.getHeight() - parent.getPaddingBottom();
    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = parent.getChildAt(i);
        RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams();
        int left = child.getRight() + layoutParams.rightMargin;
        int right = left + mDivider.getIntrinsicWidth();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 55 with LayoutParams

use of android.support.v7.widget.RecyclerView.LayoutParams in project ToolBarLib by jjhesk.

the class ToolbarHelper method renewView.

public static View renewView(Context activity, Toolbar toolbar, @LayoutRes final int layoutId) {
    toolbar.removeAllViews();
    Toolbar.LayoutParams layoutParams = new Toolbar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.gravity = Gravity.TOP;
    final View t = ToolbarHelper.generateView(layoutId, activity);
    toolbar.addView(t, layoutParams);
    return t;
}
Also used : TextView(android.widget.TextView) View(android.view.View) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

View (android.view.View)86 RecyclerView (android.support.v7.widget.RecyclerView)78 TextView (android.widget.TextView)24 ViewGroup (android.view.ViewGroup)23 ImageView (android.widget.ImageView)20 LayoutParams (android.support.v7.widget.RecyclerView.LayoutParams)13 FrameLayout (android.widget.FrameLayout)10 Toolbar (android.support.v7.widget.Toolbar)9 Rect (android.graphics.Rect)8 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)8 LinearLayout (android.widget.LinearLayout)8 BindView (butterknife.BindView)8 ActionMenuView (android.support.v7.widget.ActionMenuView)7 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)7 MarginLayoutParams (android.view.ViewGroup.MarginLayoutParams)6 EditText (android.widget.EditText)6 CollapsibleActionView (android.support.v7.view.CollapsibleActionView)5 MenuView (android.support.v7.view.menu.MenuView)5 ImageView (carbon.widget.ImageView)5 TextView (carbon.widget.TextView)5