I am creating a dynamic table whose rows contains a imageview and a textview. My problem is this imageview is taking full size of original image but I want to change the size of imageview.I have used setLayoutParams which has no effect.
As an alternative I also used textview instead of imageview and set image as textview's background and used setWidth and setHeight but it has the same problem.
Plz Help Me.
Have you tried the scaleType-Attribute?
Check out the setMaxWidth and setMaxHeight-methods of the ImageView-class:
To set an image to be a maximum of 100
x 100 while preserving the original
aspect ratio, do the following: 1) set
adjustViewBounds to true 2) set
maxWidth and maxHeight to 100 3) set
the height and width layout params to
WRAP_CONTENT.
Link
Assuming your image is a drawable resource, you can use ScaleDrawable instead, and use the xml attributes android:scaleHeight and android:scaleWidth to shrink your image.
OK I found the Solution
Resizing an ImageView within a TableLayout programmatically
Try changing your ImageView's layout_width and layout_height inside the layout file to some constant values measured in sp, for example 100sp. This will make all ImageViews look the same.
Related
I have a GridView containing ImageView all of the same size.
Each ImageView has its width set to wrap_content, so that I can support multiple screen resolutions by picking the correct version of my Drawable resource.
I can't find a way to automatically set the column size of my GridView to the ImageView's width.
This can probably be done programmatically using
mGridView.setColumnsWidth(mImageView.getWidth());
but I can't find a way to do it using only XML. Does such way exists?
Try this:
android:stretchMode="columnWidth"
Try this-
android:columnWidth="50dp"
Here you can give the dimension.
Things looked quite simple first but in the end the result is not good.
I have an image which has a width larger than screen's width. So I need to scale it down in my imageview. I looked over the ScaleType options and tried them all but none is ok. First "center" only displays the image centered on the layout, no scaling done. "fitCenter" scales the image to fit in my layout but has a major drawback: the height of the item remains as it would have the large image in it. Take a look at the second screen in the attached image. How can I force the list item, to reduce its height to wrap both the text and the image ?
Use the scaletype which seems best to you ( I guess you like what you see with fitCenter). The additional thing that you must do is
android:adjustViewBounds="true"
in your ImageView.
or you could go with FitXY but sometimes the result is not exactly what you want.
use android:scaleType="fitXY"
Could you use FitXY?
This would work if you knew the size of the area you were putting the image into.
CentreInside may also work, I've used this to scale down images, but I think it depends if you've control of the size of the bounding layout element.
You either need to set android:height = "wrap_content" on your outer container, or set static height of TextBox and give ImageView android:weight = "1" so that the ImageView takes remaining space in container.
I'm trying to make a LinearLayout that has height = LayoutParams.WRAP_CONTENT.
I am receiving an arbitrarily sized bitmap from a server to set as the background image for the LinearLayout.
How do I set the background image of the LinearLayout without resizing the view if the received bitmap is larger than the contents of the linear layout?
It would be nice if the background image could maintain its aspect ratio, and scale to match the width of the screen.
I tried overriding onMeasure as a temporary solution, but that just wound up biting me.
how about using an imageView inside your layout , which also has its adjustViewBounds set to true in order to keep aspect ratio?
Can I using xml layout attributes put image to the following position? Or I must calculate position on src?
http://i.stack.imgur.com/gox4d.png
You can do it using the XML attributes.
Just use follwing attribute in your ImageView:
Android:layout_marginTop="20dip"
Android:layout_height="20dip"
Only use DIP as these are density independent Pixels
dont use PX.
Yes, you can, for the simple example you posted I would use a vertical LinearLayout, with a FrameLayouts to 'fill' the blank space. Set the LinearLayout weightSum to 1, then set the first FrameLayout weight attribute to 0.2 (1/5), and imageview to 0.2. Also set both the frame layout and imageview layout_height values to 0px.
While this solution works, I'm sure there is a better and cleaner way out there. Hopefully someone will post it.
You can use AbsoluteLayout, calculate exact coordinates based on screen size and orientation and then position the image with absolute coordinates.
You can just use weights for different containers in a vertical linear layout.
I would like to find the dimensions of an ImageView to use to scale a Bitmap, prior to to calling view.setImageBitmap. ImageView.getWidth and ImageView.getHeight return 0 if no image has been set. (Presumably because the ImageView has not yet been measured?). Is there anyway to determine the dimensions of the ImageView prior to setting the Bitmap?
Thank you
If it's layout parameters (i.e. layout_width and layout_height) are set to wrap_content then the returned value is totally correct. You have to specify minWidth and minHeight in the XML or throught Java but then you know the minimum dimensions anyway.