ImageView scaling doesn't work
ImageView scaling doesn't work
I googled this question but didn't fond answer for me.
And this this ImageView in xml:
How I can scale this image like on example image?
P.S. This image I download from internet.
UPD 1. ImageLoader code added.
DisplayImageOptions options = new DisplayImageOptions.Builder() .showImageForEmptyUri(R.drawable.place_holder16_9) .cacheInMemory(true) .cacheOnDisk(true) .build(); ImageLoader.getInstance().displayImage(promo.getImageBigUrl(), mCoverImageView, options);
Answer by Mukesh Rana for ImageView scaling doesn't work
Try using ScaleType attribute for your ImageView in your xml. For example
android:scaleType="centerCrop".
Answer by piotrek1543 for ImageView scaling doesn't work
Sorry, but you cannot make it bigger as you use this:
android:layout_width="match_parent"
It already means "take how much width as you can". As your width has the maximum value, your image height also takes a maximum value.
You can check it by using:
android:scaleX="3" android:scaleY="3"
It should make it bigger three times. If it won't work use:
android:scaleX="0.2" android:scaleY="0.2"
It should make it smaller five times. I'm pretty sure that it would work
Hope it help
Answer by Biju Parvathy for ImageView scaling doesn't work
Set LayoutParams
from code.
ImageView image = new ImageView(this); image.setImageResource(getResources().getIdentifier('file_name', "drawable", getPackageName())); image.setAdjustViewBounds(true); image.setScaleType(ImageView.ScaleType.CENTER_CROP); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); image.setLayoutParams(layoutParams); parent.addView(image);
It's a known issue with ImageView, which won't upscale small images.
Answer by Rohit Sharma for ImageView scaling doesn't work
Try this code:
private void scaleImage(ImageView view, int boundBoxInDp) { // Get the ImageView and its bitmap Drawable drawing = view.getDrawable(); Bitmap bitmap = ((BitmapDrawable)drawing).getBitmap(); // Get current dimensions int width = bitmap.getWidth(); int height = bitmap.getHeight(); // Determine how much to scale: the dimension requiring less scaling is // closer to the its side. This way the image always stays inside your // bounding box AND either x/y axis touches it. float xScale = ((float) boundBoxInDp) / width; float yScale = ((float) boundBoxInDp) / height; float scale = (xScale <= yScale) ? xScale : yScale; // Create a matrix for the scaling and add the scaling data Matrix matrix = new Matrix(); matrix.postScale(scale, scale); // Create a new bitmap and convert it to a format understood by the ImageView Bitmap scaledBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); BitmapDrawable result = new BitmapDrawable(scaledBitmap); width = scaledBitmap.getWidth(); height = scaledBitmap.getHeight(); // Apply the scaled bitmap view.setImageDrawable(result); // Now change ImageView's dimensions to match the scaled image LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams(); params.width = width; params.height = height; view.setLayoutParams(params); } private int dpToPx(int dp) { float density = getApplicationContext().getResources().getDisplayMetrics().density; return Math.round((float)dp * density); }
Answer by Shoeb Siddique for ImageView scaling doesn't work
You can set Bitmap as background.
// Load image, decode it to Bitmap and return Bitmap to callback imageLoader.loadImage(imageUri, new SimpleImageLoadingListener() { @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { // Do whatever you want with Bitmap mCoverImageView.setBackground(new BitmapDrawable(getResources(), bitmap)); } });
Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72
0 comments:
Post a Comment