Java Code Examples for androidx.appcompat.widget.AppCompatImageView#setLayoutParams()

The following examples show how to use androidx.appcompat.widget.AppCompatImageView#setLayoutParams() . 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: CircularProgressIcon.java    From Mysplash with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void initialize() {
    image = new AppCompatImageView(getContext());
    image.setBackgroundColor(Color.TRANSPARENT);
    LayoutParams imageParams = new LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
    );
    int imageMargin = getResources().getDimensionPixelSize(R.dimen.little_margin);
    imageParams.setMargins(imageMargin, imageMargin, imageMargin, imageMargin);
    image.setLayoutParams(imageParams);
    addView(image);

    progress = new CircularProgressView(getContext());
    progress.setIndeterminate(true);
    progress.setColor(Color.WHITE);
    LayoutParams progressParams = new LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
    );
    int progressMargin = (int) new DisplayUtils(getContext()).dpToPx(5);
    progressParams.setMargins(progressMargin, progressMargin, progressMargin, progressMargin);
    progress.setLayoutParams(progressParams);
    addView(progress);

    forceSetResultState(android.R.color.transparent);
}
 
Example 2
Source File: RatingBar.java    From Kore with Apache License 2.0 5 votes vote down vote up
private FrameLayout createStar(Context context, AttributeSet attrs, int defStyle) {
    FrameLayout frameLayout = new FrameLayout(getContext());
    frameLayout.setLayoutParams(new LayoutParams(WRAP_CONTENT, MATCH_PARENT));

    AppCompatImageView ivStarBackground = new AppCompatImageView(context, attrs, defStyle);
    ivStarBackground.setLayoutParams(new LayoutParams(WRAP_CONTENT, MATCH_PARENT));
    ivStarBackground.setImageResource(iconResourceId);
    ivStarBackground.setAdjustViewBounds(true);
    ImageViewCompat.setImageTintList(ivStarBackground, ColorStateList.valueOf(backgroundColor));
    frameLayout.addView(ivStarBackground);

    ClipDrawable clipDrawable = new ClipDrawable(
            ContextCompat.getDrawable(context, iconResourceId),
            Gravity.START,
            ClipDrawable.HORIZONTAL);

    AppCompatImageView ivStarForeground = new AppCompatImageView(context, attrs, defStyle);
    ivStarForeground.setLayoutParams(new LayoutParams(WRAP_CONTENT, MATCH_PARENT));
    ivStarForeground.setImageDrawable(clipDrawable);
    ivStarForeground.setAdjustViewBounds(true);
    ImageViewCompat.setImageTintList(ivStarForeground, ColorStateList.valueOf(foregroundColor));
    frameLayout.addView(ivStarForeground);

    clipDrawables.add((ClipDrawable) ivStarForeground.getDrawable());

    return frameLayout;
}
 
Example 3
Source File: Banner.java    From MaterialBanner with Apache License 2.0 4 votes vote down vote up
private void initViewGroup(Context context) {
    // CONTENT CONTAINER
    LayoutParams layoutParams = new LayoutParams(MATCH_PARENT, WRAP_CONTENT);

    mContentContainer = new RelativeLayout(context);
    mContentContainer.setId(R.id.mb_container_content);
    mContentContainer.setLayoutParams(layoutParams);

    // ICON VIEW
    RelativeLayout.LayoutParams relativeLayoutParams = new RelativeLayout.LayoutParams(
            mIconSize, mIconSize);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        relativeLayoutParams.setMarginStart(mIconMarginStart);
        relativeLayoutParams.addRule(ALIGN_PARENT_START, TRUE);
    } else {
        relativeLayoutParams.leftMargin = mIconMarginStart;
        relativeLayoutParams.addRule(ALIGN_PARENT_LEFT, TRUE);
    }

    mIconView = new AppCompatImageView(context);
    mIconView.setId(R.id.mb_icon);
    mIconView.setLayoutParams(relativeLayoutParams);
    mIconView.setVisibility(GONE);

    // MESSAGE VIEW
    relativeLayoutParams = new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        relativeLayoutParams.setMarginStart(mMessageMarginStart);
        relativeLayoutParams.addRule(ALIGN_PARENT_START, TRUE);
    } else {
        relativeLayoutParams.leftMargin = mMessageMarginStart;
        relativeLayoutParams.addRule(ALIGN_PARENT_LEFT, TRUE);
    }

    mMessageView = new MessageView(context);
    mMessageView.setId(R.id.mb_message);
    mMessageView.setLayoutParams(relativeLayoutParams);

    // BUTTONS CONTAINER
    relativeLayoutParams = new RelativeLayout.LayoutParams(WRAP_CONTENT, WRAP_CONTENT);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        relativeLayoutParams.addRule(ALIGN_PARENT_END, TRUE);
    } else {
        relativeLayoutParams.addRule(ALIGN_PARENT_RIGHT, TRUE);
    }

    mButtonsContainer = new ButtonsContainer(context);
    mButtonsContainer.setId(R.id.mb_container_buttons);
    mButtonsContainer.setLayoutParams(relativeLayoutParams);

    mLeftButton = mButtonsContainer.getLeftButton();
    mRightButton = mButtonsContainer.getRightButton();

    // LINE
    layoutParams = new LayoutParams(MATCH_PARENT, mLineHeight);

    mLine = new View(context);
    mLine.setId(R.id.mb_line);
    mLine.setLayoutParams(layoutParams);

    addView(mContentContainer);
    addView(mLine);

    mContentContainer.addView(mIconView);
    mContentContainer.addView(mMessageView);
    mContentContainer.addView(mButtonsContainer);
}
 
Example 4
Source File: AttachmentGallery.java    From mage-android with Apache License 2.0 4 votes vote down vote up
void addAttachment(ViewGroup gallery, final Attachment a) {
    final AppCompatImageView iv = new AppCompatImageView(context);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width, height);
    iv.setLayoutParams(lp);
    iv.setBackgroundColor(ResourcesCompat.getColor(context.getResources(), R.color.background_attachment, context.getTheme()));
    lp.setMargins(0, 16, 25, 16);
    iv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (attachmentClickListener != null) {
                attachmentClickListener.onAttachmentClick(a);
            }
        }
    });
    gallery.addView(iv);

    CircularProgressDrawable progress = new CircularProgressDrawable(context);
    progress.setStrokeWidth(10f);
    progress.setCenterRadius(width / 4);
    progress.setColorSchemeColors(context.getResources().getColor(R.color.md_blue_600), context.getResources().getColor(R.color.md_orange_A200));
    progress.start();

    boolean isVideo = false;
    if (a.getLocalPath() != null) {
        String fileExtension = MimeTypeMap.getFileExtensionFromUrl(a.getLocalPath());
        String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension.toLowerCase());
        isVideo = mimeType.startsWith("video/");
    } else if (a.getContentType() != null) {
        isVideo = a.getContentType().startsWith("video/");
    }

    Collection<BitmapTransformation> transformations = new ArrayList<>();
    transformations.add(new CenterCrop());
    if (isVideo) {
        transformations.add(new VideoOverlayTransformation(context));
    }

    GlideApp.with(context)
            .asBitmap()
            .load(a)
            .placeholder(progress)
            .fallback(R.drawable.ic_attachment_200dp)
            .error(R.drawable.ic_attachment_200dp)
            .transforms(transformations.toArray(new BitmapTransformation[]{}))
            .into(iv);
}