Search in sources :

Example 91 with LayoutParams

use of android.support.v7.app.ActionBar.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 92 with LayoutParams

use of android.support.v7.app.ActionBar.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 93 with LayoutParams

use of android.support.v7.app.ActionBar.LayoutParams in project SmartCampus by Vegen.

the class RecyclerAdapter method onCreateViewHolder.

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    if (viewType == TYPE_ITEM) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_information_item, parent, false);
        view.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        return new ItemViewHolder(view);
    } else if (viewType == TYPE_FOOTER) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_item_foot, parent, false);
        view.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        return new FooterViewHolder(view);
    }
    return null;
}
Also used : LayoutParams(android.support.v7.widget.RecyclerView.LayoutParams) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View)

Example 94 with LayoutParams

use of android.support.v7.app.ActionBar.LayoutParams in project AisenWeiBo by wangdan.

the class BasicRecycleViewAdapter method onCreateViewHolder.

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View convertView;
    IITemView<T> itemView;
    if (isFooterType(viewType)) {
        itemView = footerItemView;
        convertView = itemView.getConvertView();
        if (ownerFragment.getRefreshView() != null && ownerFragment.getRefreshView() instanceof RecyclerView) {
            RecyclerView recyclerView = (RecyclerView) ownerFragment.getRefreshView();
            if (recyclerView.getLayoutManager() instanceof StaggeredGridLayoutManager) {
                StaggeredGridLayoutManager.LayoutParams layoutParams;
                if (convertView.getLayoutParams() == null || !(convertView.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams)) {
                    layoutParams = new StaggeredGridLayoutManager.LayoutParams(StaggeredGridLayoutManager.LayoutParams.MATCH_PARENT, StaggeredGridLayoutManager.LayoutParams.WRAP_CONTENT);
                    convertView.setLayoutParams(layoutParams);
                } else {
                    layoutParams = (StaggeredGridLayoutManager.LayoutParams) convertView.getLayoutParams();
                }
                if (!layoutParams.isFullSpan()) {
                    layoutParams.setFullSpan(true);
                }
            }
        }
    } else if (isHeaderType(viewType)) {
        convertView = headerItemViewCreator.newContentView(activity.getLayoutInflater(), parent, viewType);
        itemView = headerItemViewCreator.newItemView(convertView, viewType);
        convertView.setTag(R.id.itemview, itemView);
    } else {
        convertView = itemViewCreator.newContentView(activity.getLayoutInflater(), parent, viewType);
        itemView = itemViewCreator.newItemView(convertView, viewType);
        convertView.setTag(R.id.itemview, itemView);
    }
    itemView.onBindView(convertView);
    if (!(itemView instanceof ARecycleViewItemView)) {
        throw new RuntimeException("RecycleView只支持ARecycleViewItemView,请重新配置");
    }
    return (ARecycleViewItemView) itemView;
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) IITemView(org.aisen.android.ui.fragment.itemview.IITemView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 95 with LayoutParams

use of android.support.v7.app.ActionBar.LayoutParams in project RvBindAdapter by sswukang.

the class SideAndStickyHeaderRecyclerView method init.

private void init() {
    recyclerView = new RecyclerView(getContext());
    recyclerView.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    addView(recyclerView);
    sideBar = new SideBar(getContext());
    sideBar.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    sideBar.setPadding(0, 0, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics()), 0);
    addView(sideBar);
    linkageMove(false);
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

View (android.view.View)140 RecyclerView (android.support.v7.widget.RecyclerView)127 TextView (android.widget.TextView)46 ImageView (android.widget.ImageView)38 ViewGroup (android.view.ViewGroup)33 LinearLayout (android.widget.LinearLayout)27 LayoutParams (android.support.v7.widget.RecyclerView.LayoutParams)17 Paint (android.graphics.Paint)15 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)15 FrameLayout (android.widget.FrameLayout)15 BindView (butterknife.BindView)12 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)11 Toolbar (android.support.v7.widget.Toolbar)11 Rect (android.graphics.Rect)9 EditText (android.widget.EditText)9 OrientationHelperEx (com.alibaba.android.vlayout.OrientationHelperEx)9 AdapterView (android.widget.AdapterView)8 RelativeLayout (android.widget.RelativeLayout)8 VirtualLayoutManager (com.alibaba.android.vlayout.VirtualLayoutManager)8 SuppressLint (android.annotation.SuppressLint)7