ImageView width and height does not work - android

I use an ImageView in my Relative Layout.
This is the Code:
<ImageView
android:id="#+id/jpicture_imageView"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/jName_TextView"
android:layout_centerVertical="true"
android:layout_marginTop="20dp"
android:adjustViewBounds="true"
android:cropToPadding="true"
android:scaleType="fitXY" />
For testing purpose, I set width and height to 10dp, but the picture is always it's original size.
What am doing wrong?

When doing this kind of resizing stuff try going from crap and adding attributes little by little (when you are not sure what you are doing ;)
<ImageView
android:id="#+id/jpicture_imageView"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/jName_TextView"
android:layout_centerVertical="true"
android:layout_marginTop="20dp"
android:adjustViewBounds="true"
android:cropToPadding="true"
android:scaleType="fitXY" />
This part can be the problem :
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/jName_TextView"
android:layout_centerVertical="true"
You align the view left and right, below another view and center vertically.
With the attibutes fitXY and adjustViewBounds the view will not be only 10dp. Try changing those attributes.
Delete them and add them again one by one to see the changes for yourself

the part with
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
was the problem. Removing one of them fixed it.
Thanks for yur answers.
Best regards,
Peter

Related

How to rotate ImageView and have its size adjust automatically?

Image 1 is without rotation,I want image 3 when I rotate ImageView, but something like image 2 is displaying. How can I have the ImageView change its dimensions automatically?
My guess is that after rotation, the width and height of the ImageView is preserved, and I do not want that
P.S. I don't want to change the orientation of the layout
here is the picture(Rectangle is the phone, person is the imageview)
Here is my xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:id="#+id/page">
<ImageView
android:scaleType="centerInside"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/character"
android:rotation="90"
/>
</FrameLayout>
<!-- I tried all scaleTypes, and set height/width to fill_parent, wrap_content,and match_parent nothing worked-->
any help is appreciated. thanks!
Remove adjustViewBounds and use scaleType fitCenter. It should work. Try this:
<ImageView
android:scaleType="fitCenter"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/character"
android:rotation="90"
/>
Try this:
<ImageView
android:scaleType="fitCenter"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/character"
android:adjustViewBounds="true"
android:rotation="90"
/>
Edit:
android:adjustViewBounds="true"
will set scaleType="fitCenter", so I think you should try scaleType or adjustBounds ,no both.
<ImageView
android:scaleType="fitCenter"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/character"
android:rotation="90"
/>

ImageView bounds extend beyond image

I have an ImageView defined as:
<ImageView
android:id="#+id/imageView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|top"
android:layout_marginBottom="50dp"
android:layout_marginTop="-80dp"
android:layout_toRightOf="#+id/prem_BACK"
android:layout_weight="0"
android:clickable="true"
android:paddingBottom="0dp"
android:src="#drawable/tester"
android:adjustViewBounds="false" />
and I see this in Android Studio in the layout preview:
And notice the bounds of the ImageView. Is it possible to have the bounds be along the actual edges of the image I am displaying?
<ImageView
android:id="#+id/imageView"
android:src="#drawable/tester"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"/>
Adding the scaleType to centerCrop should fix it for you. You can change the centerCrop to any other suggestions according to your need.
you have to set the scaletype to fitCenter
<ImageView
android:id="#+id/imageView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|top"
android:layout_marginBottom="50dp"
android:layout_marginTop="-80dp"
android:layout_toRightOf="#+id/prem_BACK"
android:layout_weight="0"
android:clickable="true"
android:paddingBottom="0dp"
android:src="#drawable/tester"
android:adjustViewBounds="false"
android:scaleType="fitCenter"
/>
set android:adjustViewBounds="true"
It will set the bounds of the imageView to match the content
I think, the image is too large and you re wraping it so the imageview layout will be larger than you wanted to. Crop the image seems like the only solution you can do. You can try to scale

How to show original size of the image without it being stretched in Android?

Sorry for the my English, Actually the problem is that i get the images through json in android but when i show it in full size the image got stretched can you please tell me what to do??
this is my xml file
<ImageView
android:id="#+id/portFullImage"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="115dp"
android:layout_marginLeft="18dp"
android:layout_marginRight="22dp"
android:layout_marginTop="70dp"
android:src="#drawable/logo" />
maybe you can try with scaleType in your ImageView
<ImageView
android:scaleType="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/logo" />
You have specified top and bottom margins by using android:layout_marginTop="70dp" and android:layout_marginBottom="115dp" which are very big amount of space if device is small in my opinion. it will make your ImageView already small.
If you don't bother about it, try android:scaleType="centerInside" and see if it helps. You may try other scaletypes mentioned in below reference document and check the results.
Reference:
Various ScaleType of ImageView , ScaleType

How do I remove extra space above and below imageView?

I have a really simple image within a RelativeLayout and for some reason I am getting extra spacing on the top and bottom which I can't remove. How can I clear it out?
Here is what it looks like:
Here is the code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/slice11pp" />
</RelativeLayout>
Try this
android:adjustViewBounds="true"
In your above imageView just add android:scaleType="fitXY"
Your problem is probably that you have no scale type set... Add it to the XML for the ImageView, "fitCenter" should be correct, but there are others, check: ScaleType.
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/slice11pp"
android:scaleType="fitCenter" />
Must be enough adding the property:
android:adjustViewBounds="true"
for example:
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/slice11pp"
android:adjustViewBounds="true" />
If your image view height is match_parent, even if you set android:adjustViewBounds="true" ImageView will add some extra blank space at top and bottom side. so, change ImageView height to wrap_content and set android:adjustViewBounds="true"
for example
<ImageView
android:id="#+id/img_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"/>
Use drawable-nodpi folder if there is no specific requirement for images. Then android: adjustViewBounds = "true" acts as the default.
If you use drawable-nodpi you don't need to set android:adjustViewBounds = "true".
I think this is the most effortless method.
android:scaleType="centerCrop" by adding this
<ImageView
android:id="#+id/image"
android:layout_width="200dp"
android:layout_height="200dp"
android:src="#drawable/temp_image"
android:adjustViewBounds="true"
android:scaleType="centerCrop"/>
works for me Before and After Image
this line of code will solve the problem
android:adjustViewBounds="true"
don't forget to rotate the image
just add ScaleType="fitxy" inside the Image view
Try this
<ImageView
(...)
android:adjustViewBounds="true" />
this is the perfect solution
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitXY"
/>
it will not leave any extra single dp in any side. however the image will be distorted if it is not portrait image.

Android: layout issue with Image Views

I am keeping three image views with 3 different images of the same height. My code is as mentioned below..
<LinearLayout
android:id="#+id/LinearLayout06"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left" android:layout_gravity="center_vertical|center_horizontal">
<ImageView
android:id="#+id/stopServiceButton"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#null"
android:paddingRight="5dp"
android:src="#drawable/stop_service_button_selector" />
<ImageView
android:id="#+id/calibrateButton"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#null"
android:padding="5dp"
android:src="#drawable/calibrate_button_selector" />
<ImageView
android:id="#+id/doneButton"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:background="#null"
android:padding="5dp"
android:src="#drawable/done_button_selector" />
</LinearLayout>
In large layouts i was able to manage these images(i dont have to use weight parameter for it) but for small layout i have to keep the weight parameter as one to fit them in the screen, but then the height changes as shown below.
Can someone help me out in this ?
the android:adjustViewBounds="true" preserves the aspect ratio of the images. since the width is to wrap content, the height gets reduced accordingly.
To reduce the blurring effect that you mentioned in your comment, you can try setting android:filter the attribute to the drawables.

Categories

Resources