Java Code Examples for android.support.v7.widget.AppCompatImageView#setLayoutParams()

The following examples show how to use android.support.v7.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: RecyclerViewBanner.java    From RecyclerViewBanner with Apache License 2.0 6 votes vote down vote up
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    AppCompatImageView img = new AppCompatImageView(parent.getContext());
    RecyclerView.LayoutParams params = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    img.setLayoutParams(params);
    img.setId(R.id.rvb_banner_image_view_id);
    img.setScaleType(AppCompatImageView.ScaleType.CENTER_CROP);
    img.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (onRvBannerClickListener != null) {
                onRvBannerClickListener.onClick(currentIndex % mData.size());
            }
        }
    });
    return new RecyclerView.ViewHolder(img) {
    };
}
 
Example 2
Source File: InstaLikeView.java    From InstaLikeView with Apache License 2.0 6 votes vote down vote up
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    mImageHeart = new AppCompatImageView(context);
    TypedArray a = context.getTheme().obtainStyledAttributes(
            attrs,
            R.styleable.InstaLikeView,
            defStyleAttr, 0);

    int likeColor = a.getColor(R.styleable.InstaLikeView_likeColor, ContextCompat.getColor(context, R.color.heartColor));
    int likeSrc = a.getResourceId(R.styleable.InstaLikeView_likeSrc, R.drawable.img_heart);
    int likeSize = a.getDimensionPixelSize(R.styleable.InstaLikeView_likeSize, getResources().getDimensionPixelSize(R.dimen.likeSize));


    LayoutParams heartParams = new LayoutParams(likeSize, likeSize);
    heartParams.addRule(CENTER_IN_PARENT, TRUE);

    mImageHeart.setLayoutParams(heartParams);
    mImageHeart.setVisibility(GONE);
    mImageHeart.setImageResource(likeSrc);
    mImageHeart.setColorFilter(likeColor);
    addView(mImageHeart);
}
 
Example 3
Source File: RadioRealButton.java    From RadioRealButton with Apache License 2.0 6 votes vote down vote up
private void initViews() {
    setLayoutParams(new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1));
    setOrientation(HORIZONTAL);
    setGravity(Gravity.CENTER);

    imageView = new AppCompatImageView(getContext());
    imageView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) {{
        gravity = Gravity.CENTER;
    }});
    setDrawableAttrs();
    addView(imageView);

    textView = new AppCompatTextView(getContext());
    textView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) {{
        gravity = Gravity.CENTER;
    }});
    setTextAttrs();
    addView(textView);
}
 
Example 4
Source File: PhotoLayout.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
private void initPreContainer(){
    preContainer=new LinearLayout(getContext());
    preContainer.setOrientation(LinearLayout.HORIZONTAL);
    LayoutParams lp=new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lp.gravity=Gravity.CENTER_VERTICAL;
    preContainer.setLayoutParams(lp);
    preContainer.setOnClickListener(this);
    AppCompatImageView tmpImageView=new AppCompatImageView(getContext());
    tmpImageView.setBackgroundResource(R.mipmap.ic_image_black_24dp);
    AppCompatTextView tmpTextView=new AppCompatTextView(getContext());
    LinearLayout.LayoutParams lp1=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lp1.gravity=Gravity.CENTER_VERTICAL;
    tmpImageView.setLayoutParams(lp1);
    tmpTextView.setLayoutParams(lp1);
    tmpTextView.setText(getContext().getString(R.string.select_photo));
    preContainer.addView(tmpImageView);
    preContainer.addView(tmpTextView);
    this.addView(preContainer);
}
 
Example 5
Source File: PhotoLayout.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
private void initImgContainer(){
    LinearLayout linearLayout=new LinearLayout(getContext());
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    imageView=new AppCompatImageView(getContext());
    LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    imageView.setLayoutParams(lp);
    linearLayout.addView(imageView);
    imageView.setOnClickListener(this);
    editText=new AppCompatEditText(getContext());
    linearLayout.addView(editText);
    editText.setVisibility(GONE);
    editText.setTextAppearance(getContext(),R.style.NoteTextAppearance);
    editText.setGravity(Gravity.CENTER);
    editText.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if(keyCode==KeyEvent.KEYCODE_DEL&&editText.getText().toString().isEmpty()){
                editText.setVisibility(GONE);
            }
            return false;
        }
    });
    this.addView(linearLayout);
}
 
Example 6
Source File: ScreenshotsAdapter.java    From YTS with MIT License 5 votes vote down vote up
@NonNull @Override public Object instantiateItem(@NonNull ViewGroup container, int position) {
  AppCompatImageView imageView = new AppCompatImageView(container.getContext());
  ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(WRAP_CONTENT, MATCH_PARENT);
  imageView.setLayoutParams(params);
  imageView.setPadding(12, 0, 12, 0);
  imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
  container.addView(imageView);

  loadImage(imageView, position);
  return imageView;
}
 
Example 7
Source File: Fingerprint.java    From Fingerprint with MIT License 5 votes vote down vote up
private void initView(Context context){
    this.fingerprintManager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
    this.cipherHelper = null;
    this.handler = new Handler();
    this.fingerprintCallback = null;
    this.fingerprintSecureCallback = null;
    this.counterCallback = null;
    this.cryptoObject = null;
    this.tryCounter = 0;
    this.delayAfterError = DEFAULT_DELAY_AFTER_ERROR;

    int fingerprintSize = (int) (size*SCALE);
    int circleSize = size;

    fingerprintImageView = new AppCompatImageView(context);
    fingerprintImageView.setLayoutParams(new RelativeLayout.LayoutParams(fingerprintSize, fingerprintSize));
    fingerprintImageView.setBackgroundResource(R.drawable.fingerprint);
    ((RelativeLayout.LayoutParams)fingerprintImageView.getLayoutParams()).addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);

    circleView = new View(context);
    circleView.setLayoutParams(new RelativeLayout.LayoutParams(circleSize, circleSize));
    circleView.setBackgroundResource(R.drawable.circle);
    ((RelativeLayout.LayoutParams)circleView.getLayoutParams()).addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);

    setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
    addView(circleView);
    addView(fingerprintImageView);

    setStatus(R.drawable.fingerprint, fingerprintScanning, circleScanning);
}
 
Example 8
Source File: ProSwipeButton.java    From proSwipeButton with MIT License 5 votes vote down vote up
public void showResultIcon(boolean isSuccess, boolean shouldReset) {
    animateFadeHide(context, progressBar);

    final AppCompatImageView failureIcon = new AppCompatImageView(context);
    RelativeLayout.LayoutParams icLayoutParams =
            new RelativeLayout.LayoutParams(dpToPx(50), dpToPx(50));
    failureIcon.setLayoutParams(icLayoutParams);
    failureIcon.setVisibility(GONE);
    int icon;
    if (isSuccess)
        icon = R.drawable.ic_check_circle_36dp;
    else
        icon = R.drawable.ic_cancel_full_24dp;
    failureIcon.setImageResource(icon);
    contentContainer.addView(failureIcon);
    animateFadeShow(context, failureIcon);

    if (shouldReset) {
        // expand the btn again
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                animateFadeHide(context, failureIcon);
                morphToRect();
                arrowHintContainer.setX(0);
                animateFadeShow(context, arrowHintContainer);
                animateFadeShow(context, contentTv);
            }
        }, 1000);
    }
}
 
Example 9
Source File: SpotlightView.java    From Spotlight with Apache License 2.0 4 votes vote down vote up
/**
 * Add arc above/below the circular target overlay.
 */
private void addArcAnimation(final Activity activity) {
    AppCompatImageView mImageView = new AppCompatImageView(activity);
    mImageView.setImageResource(R.drawable.ic_spotlight_arc);
    LayoutParams params = new LayoutParams(2 * (circleShape.getRadius() + extraPaddingForArc),
            2 * (circleShape.getRadius() + extraPaddingForArc));


    if (targetView.getPoint().y > getHeight() / 2) {//bottom
        if (targetView.getPoint().x > getWidth() / 2) {//Right
            params.rightMargin = getWidth() - targetView.getPoint().x - circleShape.getRadius() - extraPaddingForArc;
            params.bottomMargin = getHeight() - targetView.getPoint().y - circleShape.getRadius() - extraPaddingForArc;
            params.gravity = Gravity.RIGHT | Gravity.BOTTOM;
        } else {
            params.leftMargin = targetView.getPoint().x - circleShape.getRadius() - extraPaddingForArc;
            params.bottomMargin = getHeight() - targetView.getPoint().y - circleShape.getRadius() - extraPaddingForArc;
            params.gravity = Gravity.LEFT | Gravity.BOTTOM;
        }
    } else {//up
        mImageView.setRotation(180); //Reverse the view
        if (targetView.getPoint().x > getWidth() / 2) {//Right
            params.rightMargin = getWidth() - targetView.getPoint().x - circleShape.getRadius() - extraPaddingForArc;
            params.bottomMargin = getHeight() - targetView.getPoint().y - circleShape.getRadius() - extraPaddingForArc;
            params.gravity = Gravity.RIGHT | Gravity.BOTTOM;
        } else {
            params.leftMargin = targetView.getPoint().x - circleShape.getRadius() - extraPaddingForArc;
            params.bottomMargin = getHeight() - targetView.getPoint().y - circleShape.getRadius() - extraPaddingForArc;
            params.gravity = Gravity.LEFT | Gravity.BOTTOM;
        }

    }
    mImageView.postInvalidate();
    mImageView.setLayoutParams(params);
    addView(mImageView);

    PorterDuffColorFilter porterDuffColorFilter = new PorterDuffColorFilter(lineAndArcColor,
            PorterDuff.Mode.SRC_ATOP);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        AnimatedVectorDrawable avd = (AnimatedVectorDrawable)
                ContextCompat.getDrawable(activity, R.drawable.avd_spotlight_arc);
        avd.setColorFilter(porterDuffColorFilter);
        mImageView.setImageDrawable(avd);
        avd.start();
    } else {
        AnimatedVectorDrawableCompat avdc =
                AnimatedVectorDrawableCompat.create(activity, R.drawable.avd_spotlight_arc);
        avdc.setColorFilter(porterDuffColorFilter);
        mImageView.setImageDrawable(avdc);
        avdc.start();
    }

    new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
        @Override
        public void run() {
            addPathAnimation(activity);
        }
    }, 400);
}