Java Code Examples for com.google.android.flexbox.FlexboxLayout#LayoutParams

The following examples show how to use com.google.android.flexbox.FlexboxLayout#LayoutParams . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CreateChatFragment.java    From weMessage with GNU Affero General Public License v3.0 6 votes vote down vote up
public void initializeView(){
    FlexboxLayout.LayoutParams layoutParams = (FlexboxLayout.LayoutParams) getLayoutParams();
    int paddingPxVer = DisplayUtils.convertDpToRoundedPixel(paddingVerticalDp, getContext());
    int paddingPxHoz = DisplayUtils.convertDpToRoundedPixel(paddingHorizontalDp, getContext());

    layoutParams.setMarginStart(DisplayUtils.convertDpToRoundedPixel(marginHorizontalDp, getContext()));
    layoutParams.setMarginEnd(DisplayUtils.convertDpToRoundedPixel(marginHorizontalDp, getContext()));

    setFont("OrkneyLight");
    setTextSize(16);
    setTextColor(getResources().getColor(R.color.colorHeader));
    setFilters(new InputFilter[] { new InputFilter.LengthFilter(32) });
    setEllipsize(TextUtils.TruncateAt.END);
    setLayoutParams(layoutParams);
    setPadding(paddingPxHoz, paddingPxVer, paddingPxHoz, paddingPxVer);

    setOnClickListener(this);
}
 
Example 2
Source File: LayoutParamsCreator.java    From HtmlNative with Apache License 2.0 6 votes vote down vote up
public static void createLayoutParams(LayoutParamsCreator creator, ViewGroup.LayoutParams
        outParams) {
    outParams.height = creator.height;
    outParams.width = creator.width;
    if (outParams instanceof HNDivLayout.HNDivLayoutParams) {
        ((HNDivLayout.HNDivLayoutParams) outParams).setMargins(creator.marginLeft, creator
                .marginTop, creator.marginRight, creator.marginBottom);
        ((HNDivLayout.HNDivLayoutParams) outParams).positionMode = creator.positionMode;
        ((HNDivLayout.HNDivLayoutParams) outParams).left = creator.left;
        ((HNDivLayout.HNDivLayoutParams) outParams).top = creator.top;
        ((HNDivLayout.HNDivLayoutParams) outParams).bottom = creator.bottom;
        ((HNDivLayout.HNDivLayoutParams) outParams).right = creator.right;
    } else if (outParams instanceof FlexboxLayout.LayoutParams) {
        //TODO complete
    } else if (outParams instanceof ViewGroup.MarginLayoutParams) {
        ((ViewGroup.MarginLayoutParams) outParams).setMargins(creator.marginLeft, creator
                .marginTop, creator.marginRight, creator.marginBottom);

    } else {
        throw new IllegalArgumentException("can't create related layoutParams, unknown " +
                "layoutParams type " + outParams.toString());
    }
}
 
Example 3
Source File: ReadFragment.java    From GankGirl with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void onDataChild(List<ReadChildTypeBean> datas) {
    View mHeaderView = inflate(getContext(), R.layout.recycler_header_read, null);
    FlexboxLayout flexboxLayout = findById(mHeaderView, R.id.flexboxLayout);
    if (flexboxLayout.getRootView() == null)
        return;
    flexboxLayout.removeAllViews();

    for (ReadChildTypeBean data : datas) {
        ImageView imageView = new ImageView(getContext());
        FlexboxLayout.LayoutParams layoutParams = new FlexboxLayout.LayoutParams(DensityUtils.dip2px(getContext(), 30), DensityUtils.dip2px(getContext(), 30));
        imageView.setLayoutParams(layoutParams);
        imageView.setOnClickListener(v -> ReadMoreActivity.start(getContext(),data.getUrl(),data.getTitle(),data.getImg()));
        flexboxLayout.addView(imageView);

        int size = DensityUtils.dip2px(getContext(), 10);
        FlexboxLayout.LayoutParams layoutParam = (FlexboxLayout.LayoutParams) imageView
                .getLayoutParams();
        layoutParam.setMargins(size, size, size, 0);
        imageView.setLayoutParams(layoutParam);
        GlideImageLoader.loadAdapterCircle(getContext(), data.getImg(), imageView);
    }
    RecyclerViewUtils.setHeaderView(recyclerView, mHeaderView);
}
 
Example 4
Source File: BackupKeyActivity.java    From alpha-wallet-android with MIT License 5 votes vote down vote up
private TextView generateSeedWordTextView(String word) {
    int margin = Utils.dp2px(this, 4);
    int padding;
    float textSize;
    int textViewHeight;

    if (screenWidth > 800) {
        textSize = 16.0f;
        padding = Utils.dp2px(this, 20);
        textViewHeight = Utils.dp2px(this, 44);
    } else {
        textSize = 14.0f;
        padding = Utils.dp2px(this, 16);
        textViewHeight = Utils.dp2px(this, 38);
    }

    FlexboxLayout.LayoutParams params =
            new FlexboxLayout.LayoutParams(FlexboxLayout.LayoutParams.WRAP_CONTENT, textViewHeight);

    params.setMargins(margin, margin, margin, margin);
    TextView seedWord = new TextView(this);
    seedWord.setMaxLines(1);
    seedWord.setText(word);
    seedWord.setTypeface(ResourcesCompat.getFont(this, R.font.font_regular));
    seedWord.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize);
    seedWord.setBackgroundResource(R.drawable.background_seed_word);
    seedWord.setTextColor(getColor(R.color.mine));
    seedWord.setLayoutParams(params);
    seedWord.setGravity(Gravity.CENTER);
    seedWord.setPadding(padding, 0, padding, 0);

    return seedWord;
}
 
Example 5
Source File: ShadowViewActivity.java    From YCCardView with Apache License 2.0 5 votes vote down vote up
private View createView(LayoutInflater inflater, int position) {
    View view = inflater.inflate(R.layout.view_item_color, (ViewGroup) flexboxLayout, false);
    view.setTag(position);
    FlexboxLayout.LayoutParams p = new FlexboxLayout.LayoutParams(dp2px(42f, itemView.getContext()), dp2px(24f, itemView.getContext()));
    int margin = dp2px(4f, itemView.getContext());
    p.setMargins(margin, margin, margin, margin);
    flexboxLayout.addView(view, p);
    return view;
}
 
Example 6
Source File: SponsorsFragment.java    From droidkaigi2016 with Apache License 2.0 5 votes vote down vote up
private void addView(Sponsor sponsor, FlexboxLayout container) {
    SponsorImageView imageView = new SponsorImageView(getActivity());
    imageView.bindData(sponsor, v -> {
        if (TextUtils.isEmpty(sponsor.url))
            return;
        analyticsTracker.sendEvent("sponsor", sponsor.url);
        AppUtil.showWebPage(getActivity(), sponsor.url);
    });
    FlexboxLayout.LayoutParams params = new FlexboxLayout.LayoutParams(
            FlexboxLayout.LayoutParams.WRAP_CONTENT, FlexboxLayout.LayoutParams.WRAP_CONTENT);
    int margin = (int) getResources().getDimension(R.dimen.spacing_small);
    params.setMargins(margin, margin, 0, 0);
    container.addView(imageView, params);
}
 
Example 7
Source File: SponsorsFragment.java    From droidkaigi2016 with Apache License 2.0 5 votes vote down vote up
private void addView(Sponsor sponsor, FlexboxLayout container) {
    SponsorImageView imageView = new SponsorImageView(getActivity());
    imageView.bindData(sponsor, v -> {
        if (TextUtils.isEmpty(sponsor.url))
            return;
        analyticsTracker.sendEvent("sponsor", sponsor.url);
        AppUtil.showWebPage(getActivity(), sponsor.url);
    });
    FlexboxLayout.LayoutParams params = new FlexboxLayout.LayoutParams(
            FlexboxLayout.LayoutParams.WRAP_CONTENT, FlexboxLayout.LayoutParams.WRAP_CONTENT);
    int margin = (int) getResources().getDimension(R.dimen.spacing_small);
    params.setMargins(margin, margin, 0, 0);
    container.addView(imageView, params);
}
 
Example 8
Source File: LayoutParamsCreator.java    From HtmlNative with Apache License 2.0 4 votes vote down vote up
public FlexboxLayout.LayoutParams toFlexLayoutParams() {
    FlexboxLayout.LayoutParams layoutParams = new FlexboxLayout.LayoutParams(width, height);
    layoutParams.setMargins(marginLeft, marginTop, marginRight, marginBottom);
    return layoutParams;
}