Example usage for android.widget ImageView setLayoutParams

List of usage examples for android.widget ImageView setLayoutParams

Introduction

In this page you can find the example usage for android.widget ImageView setLayoutParams.

Prototype

public void setLayoutParams(ViewGroup.LayoutParams params) 

Source Link

Document

Set the layout parameters associated with this view.

Usage

From source file:com.derrick.movies.MovieDetailsActivity.java

private void setTrailers(Videos videos) {
    videosList = videos.getResults();//from   ww  w . ja va  2  s. c  om
    int size = videosList.size();
    if (size == 1) {
        txt_title_trailer.setText("Trailer");
    }

    for (int i = 0; i < size; i++) {

        Result result = videosList.get(i);
        String url = IMAGE_YOUTUBE + result.getKey() + YOUTUBE_QUALITY;
        ImageView imageView;
        ImageView imageView_play;
        TextView txt_name;

        ViewGroup.LayoutParams lp = new RelativeLayout.LayoutParams(70, 70);
        ViewGroup.LayoutParams lp2 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                RelativeLayout.LayoutParams.WRAP_CONTENT);

        RelativeLayout relativeLayout = new RelativeLayout(this);
        relativeLayout.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
                RelativeLayout.LayoutParams.MATCH_PARENT));

        if (size == 1) {
            imageView = new ImageView(getApplicationContext());
            imageView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

        } else {
            imageView = new ImageView(getApplicationContext());
            imageView
                    .setLayoutParams(new RelativeLayout.LayoutParams(500, ViewGroup.LayoutParams.MATCH_PARENT));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        }

        imageView_play = new ImageView(getApplicationContext());
        imageView_play.setLayoutParams(lp);
        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) imageView_play
                .getLayoutParams();
        layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
        imageView_play.setLayoutParams(layoutParams);
        imageView_play.setScaleType(ImageView.ScaleType.CENTER_CROP);
        Drawable drawable = getResources()
                .getDrawable(getResources().getIdentifier("play", "drawable", getPackageName()));
        imageView_play.setImageDrawable(drawable);

        txt_name = new TextView(getApplicationContext());
        txt_name.setLayoutParams(lp2);
        RelativeLayout.LayoutParams layoutParams2 = (RelativeLayout.LayoutParams) txt_name.getLayoutParams();
        layoutParams2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
        layoutParams2.setMargins(8, 8, 8, 16);
        txt_name.setLayoutParams(layoutParams2);
        txt_name.setTypeface(robotoCondensed);
        txt_name.setText(result.getName());
        txt_name.setTextColor(getResources().getColor(R.color.colorWhite));

        Glide.with(getBaseContext()).load(url).diskCacheStrategy(DiskCacheStrategy.ALL)
                .listener(new RequestListener<String, GlideDrawable>() {
                    @Override
                    public boolean onException(Exception e, String model, Target<GlideDrawable> target,
                            boolean isFirstResource) {
                        return false;
                    }

                    @Override
                    public boolean onResourceReady(GlideDrawable resource, String model,
                            Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {

                        return false;
                    }
                }).into(imageView);

        // trailerSlider.addView(imageView_play);
        relativeLayout.addView(imageView);
        relativeLayout.addView(imageView_play);
        relativeLayout.addView(txt_name);
        trailerSlider.addView(relativeLayout);

    }

}

From source file:io.vit.vitio.Settings.ComingSoonActivity.java

private void toggleCircle(ImageView imon, ImageView imoff[]) {
    imon.setActivated(true);//  ww w.jav  a2s  .c o m
    ObjectAnimator animatorX = ObjectAnimator.ofFloat(imon, "scaleX", 0.5f, 1.0f);
    ObjectAnimator animatorY = ObjectAnimator.ofFloat(imon, "scaleY", 0.5f, 1.0f);
    animatorX.setDuration(300);
    animatorY.setDuration(300);
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(animatorX, animatorY);
    animatorSet.start();
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
                    getResources().getDisplayMetrics()),
            (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
                    getResources().getDisplayMetrics()));
    params.setMargins(0, 0, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 13,
            getResources().getDisplayMetrics()), 0);
    imon.setLayoutParams(params);
    for (int i = 0; i < imoff.length; i++) {
        imoff[i].setActivated(false);
        params = new LinearLayout.LayoutParams(
                (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 6,
                        getResources().getDisplayMetrics()),
                (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 6,
                        getResources().getDisplayMetrics()));
        params.setMargins(0, 0, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 13,
                getResources().getDisplayMetrics()), 0);
        imoff[i].setLayoutParams(params);
    }
}

From source file:com.luke.lukef.lukeapp.popups.SubmissionPopup.java

/**
 * Adds imageviews to the categories section of the popup, with the thumbnails of the categories.
 * Dimensions of the parent view can only be retreived once they are drawn, so a
 * GlobalLayoutListener is needed./*from  ww  w .  j  a  va2  s.  c o  m*/
 *
 * @param categories list of categories whose images are to be added to the category list
 */
private void setCategories(List<Category> categories) {
    for (Category c : categories) {
        final ImageView categoryImg = new ImageView(this.mainActivity);
        categoryImg.setImageBitmap(c.getImage());
        final LinearLayout.LayoutParams[] layoutParams = new LinearLayout.LayoutParams[1];
        this.submissionCategoriesLinear.getViewTreeObserver()
                .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() {
                        layoutParams[0] = new LinearLayout.LayoutParams(new LinearLayout.LayoutParams(
                                SubmissionPopup.this.submissionCategoriesLinear.getHeight(),
                                SubmissionPopup.this.submissionCategoriesLinear.getHeight()));
                        categoryImg.setLayoutParams(layoutParams[0]);
                        if (categoryImg.getParent() != null) {
                            ((ViewGroup) categoryImg.getParent()).removeView(categoryImg);
                        }
                        SubmissionPopup.this.submissionCategoriesLinear.addView(categoryImg);
                    }
                });
    }
}

From source file:com.bitants.wally.views.swipeclearlayout.SwipeClearLayout.java

private View generateCircle(Context context, AttributeSet attrs, DisplayMetrics metrics) {
    ImageView view = new ImageView(context, attrs);
    GradientDrawable circle = (GradientDrawable) getResources().getDrawable(R.drawable.circle);
    circle.setColor(CIRCLE_DEFAULT_COLOR);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        view.setBackground(circle);//from  www . ja va 2s.  co m
    } else {
        view.setBackgroundDrawable(circle);
    }
    int size = (int) (metrics.density * CIRCLE_SIZE);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(size, size);
    view.setLayoutParams(params);
    view.setImageResource(R.drawable.clip_random);
    view.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    view.setRotation(90.0f);
    return view;
}

From source file:android.support.asy.image.ImageWorker.java

private void calculateImageViewHeight(String url, ImageView imageView) {
    String fileName = ((HotPotApplication) ((Activity) mContext).getApplication())
            .getCacheImageAbsolutePath(url);
    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;// ww w.  jav a  2 s .  co  m
    BitmapFactory.decodeFile(fileName, options);
    int width = options.outWidth;
    int height = options.outHeight;
    if (width != 0) {

        final int imageViewHeight = mScreenWidth * height / width;

        if (imageViewHeight != 0) {
            LayoutParams lp = imageView.getLayoutParams();
            if (lp == null) {
                lp = new LayoutParams(mScreenWidth, imageViewHeight);
                imageView.setLayoutParams(lp);
            } else {
                lp.width = mScreenWidth;
                lp.height = imageViewHeight;
            }
            imageView.invalidate();
        }
    }
}

From source file:io.vit.vitio.StartScreens.FragmentHolder.java

private void toggleCircle(ImageView imon, ImageView imoff[]) {
    imon.setActivated(true);//w  w w  .j  av  a  2 s  .c  om
    ObjectAnimator animatorX = ObjectAnimator.ofFloat(imon, "scaleX", 0.5f, 1.0f);
    ObjectAnimator animatorY = ObjectAnimator.ofFloat(imon, "scaleY", 0.5f, 1.0f);
    animatorX.setDuration(300);
    animatorY.setDuration(300);
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(animatorX, animatorY);
    animatorSet.start();
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
                    getResources().getDisplayMetrics()),
            (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
                    getResources().getDisplayMetrics()));
    if (imon != im7)
        params.setMargins(0, 0, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 13,
                getResources().getDisplayMetrics()), 0);
    imon.setLayoutParams(params);
    for (int i = 0; i < imoff.length; i++) {
        imoff[i].setActivated(false);
        params = new LinearLayout.LayoutParams(
                (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 6,
                        getResources().getDisplayMetrics()),
                (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 6,
                        getResources().getDisplayMetrics()));
        if (imoff[i] != im7)
            params.setMargins(0, 0, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 13,
                    getResources().getDisplayMetrics()), 0);
        imoff[i].setLayoutParams(params);
    }
}

From source file:com.android.contacts.group.GroupMembersFragment.java

@Override
protected View inflateView(LayoutInflater inflater, ViewGroup container) {
    final View view = inflater.inflate(R.layout.contact_list_content, /* root */ null);
    final View emptyGroupView = inflater.inflate(R.layout.empty_group_view, null);

    final ImageView image = (ImageView) emptyGroupView.findViewById(R.id.empty_group_image);
    final LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) image.getLayoutParams();
    final int screenHeight = getResources().getDisplayMetrics().heightPixels;
    params.setMargins(0,//from ww  w .j  a  va  2  s  . c  om
            screenHeight / getResources().getInteger(R.integer.empty_group_view_image_margin_divisor), 0, 0);
    params.gravity = Gravity.CENTER_HORIZONTAL;
    image.setLayoutParams(params);

    final FrameLayout contactListLayout = (FrameLayout) view.findViewById(R.id.contact_list);
    contactListLayout.addView(emptyGroupView);

    final Button addContactsButton = (Button) emptyGroupView.findViewById(R.id.add_member_button);
    addContactsButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            startActivityForResult(
                    GroupUtil.createPickMemberIntent(getContext(), mGroupMetaData, getMemberContactIds()),
                    RESULT_GROUP_ADD_MEMBER);
        }
    });
    return view;
}

From source file:gidaibero.android.matsol.MatrixDisplayActivity.java

private TableRow decorateTableRow(TableRow tableRow, int height, int width, int row) {
    ImageView leftImageView = new ImageView(this);
    ImageView rightImageView = new ImageView(this);
    leftImageView.setBackgroundResource(R.drawable.left_edge);
    rightImageView.setBackgroundResource(R.drawable.right_edge);
    if (target == R.id.matrix_button) {
        // we need to allocate two more elements
        ImageView insideLeftImageView = new ImageView(this);
        ImageView insideRightImageView = new ImageView(this);
        if (row == 0) { // should change decorators for top decorators
            leftImageView.setBackgroundResource(R.drawable.top_left_edge);
            rightImageView.setBackgroundResource(R.drawable.top_right_edge);
            insideLeftImageView.setBackgroundResource(R.drawable.top_right_edge); // this is not a mistake
            insideRightImageView.setBackgroundResource(R.drawable.top_left_edge);
        } else if (row == this.height - 1) {
            leftImageView.setBackgroundResource(R.drawable.bottom_left_edge);
            rightImageView.setBackgroundResource(R.drawable.bottom_right_edge);
            insideLeftImageView.setBackgroundResource(R.drawable.bottom_right_edge); // this is not a mistake
            insideRightImageView.setBackgroundResource(R.drawable.bottom_left_edge);

        } else {//from  ww w.j  a v  a2  s . co m
            insideRightImageView.setBackgroundResource(R.drawable.left_edge);
            insideLeftImageView.setBackgroundResource(R.drawable.right_edge);
        }
        insideLeftImageView.setLayoutParams(new LayoutParams(height, width / 5));
        insideRightImageView.setLayoutParams(new LayoutParams(height, width / 5));
        insideRightImageView.getLayoutParams().height = height;
        insideLeftImageView.getLayoutParams().height = height;
        insideRightImageView.getLayoutParams().width = width / 5;
        insideLeftImageView.getLayoutParams().width = width / 5;
        tableRow.addView(insideLeftImageView, this.width - 1);
        tableRow.addView(insideRightImageView, this.width);

    } else {
        // this is a determinant button
    }
    leftImageView.setLayoutParams(new LayoutParams(height, width / 10));
    rightImageView.setLayoutParams(new LayoutParams(height, width / 10));
    leftImageView.getLayoutParams().height = height;
    rightImageView.getLayoutParams().height = height;
    leftImageView.getLayoutParams().width = width / 5;
    rightImageView.getLayoutParams().width = width / 5;
    tableRow.addView(leftImageView, 0);
    tableRow.addView(rightImageView);
    return tableRow;
}

From source file:cn.longchou.wholesale.activity.VehicleDetailActivity.java

private void getCarMaintenanceData() {
     HttpUtils http = new HttpUtils();
     String url = Constant.RequestMaintenance + cars.carID;
     http.send(HttpMethod.POST, url, new RequestCallBack<String>() {
         @Override//from w ww  .  jav a  2s  . co  m
         public void onSuccess(ResponseInfo<String> responseInfo) {
             Gson gson = new Gson();
             MaintenanceReports json = gson.fromJson(responseInfo.result, MaintenanceReports.class);
             List<MaintenanceReports.MaintenanceReport> maintenanceReports = json.maintenanceReports;
             if (maintenanceReports != null) {
                 for (int i = 0; i < maintenanceReports.size(); i++) {
                     ImageView image = new ImageView(VehicleDetailActivity.this);
                     Glide.with(VehicleDetailActivity.this).load(maintenanceReports.get(i).imgUrl).into(image);
                     LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                             LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                     params.bottomMargin = 20;
                     image.setLayoutParams(params);
                     mLMaintenance.addView(image);
                 }
             }

         }

         @Override
         public void onFailure(HttpException e, String s) {

         }
     });
 }

From source file:com.acc.android.util.widget.adapter.ImageAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // if (false) {
    // if (this.accFileCallback == null) {
    // return null;
    // }/*from ww w  . j a  v  a  2  s . co  m*/
    ACCFile accFile = this.imageData.getAccFiles().get(position);
    ImageView imageView = !this.isBig ? new ImageView(this.context)
            : new AutoImageView(this.context, position == 0, position == this.getCount() - 1,
                    this.onSingleTapListener);
    Bitmap bitmap = this.bitmapProviderManager.getBitmap(accFile);
    // if (bitmap == null || bitmap.isRecycled()) {
    // bitmap = BitmapManager.getInstance(context).getBlankBitmap();
    // }
    // LogUtil.systemOut("bitmap == null:");
    // LogUtil.systemOut(bitmap == null);
    // if (true) {
    if (this.isBig) {
        imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
    }
    // this.isBig ?
    // :autoImageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
    imageView.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    // imageView.setBackgroundResource(R.drawable.login_input);
    // }
    // System.out.println(position);
    imageView.setImageBitmap(bitmap);
    if (this.isBig && accFile.getProgress() != null) {
        ((AutoImageView) imageView).setProgress(accFile.getProgress());
    }
    // }
    return imageView;
}