android resize image - android

I have added image in android, but it is fitting to middle of the screen, what can I do to set it for full screen?
what is wrap_content and fill parent, I'm not getting how to do this.
This is my code
<ImageView
android:scaleType="fitCenter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/my_image" android:cropToPadding="false"/>

Try this
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="center"
wrap_content says ImageView to fit image dimension and fill_parent to fit dimension of father layout.

Look for scaleType
<ImageView android:scaleType="fitCenter" />

You may try:
android:scaleType="fitXY"
Read more about ScaleType.

Related

How to make the size of ImageView independent to parent when it is larger than the parent?

for example, if a 80dp square layout contains a smaller ImageView, the size of ImageView will not be scaled:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="80dp"
android:layout_height="80dp"
android:background="#FFFF00"
android:clipChildren="true">
<ImageView
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/sym_def_app_icon" />
</RelativeLayout>
but if the parent is smaller than the ImageView, eg:30dp:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#FFFF00"
android:clipChildren="true">
<ImageView
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#android:drawable/sym_def_app_icon" />
</RelativeLayout>
it would be scaled automatically:
but I want the ImageView cropped instead of scaled:
how can I get this crop effect in xml?
There is alot of techniques available.
Try to Add both attribute in your ImageView xml
android:scaleType="matrix"
OR
Use margin-right,left,up,down.
OR
Search Icon size in google and then edit this icon in photoshop give it a fix size of icon .
try adding following attribute in your ImageView xml
android:scaleType="matrix"
hope it helps :)

Remove padding of ImageButton

How can I get an ImageButton that has a fixed height and is only as wide as it needs according to the ratio of its source image?
I tried the following:
<ImageButton
android:layout_width="wrap_content"
android:layout_height="8pt"
android:minWidth="0pt"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:src="#drawable/list_download"
android:background="#android:color/black"
android:padding="0pt"/>
I set background to black just to see the boundaries of it exactly, and here is the outcome.
I have seen some solutions that suggest to use negative paddings but it is not an elegant solution. There should be a better one.
I tried similar configurations on an ImageView too, but it also had extra padding. So it's not an ImageButton specific problem (i.e. it is not related to this nine-patch issue).
EDIT: If I change scaleType from fitCenter to fitStart, then the outcome is like this. So there is somehow a minimum width.
It's because you've set a limited height. That limits the image height, but when Android calculates the width of the content (the original unrezised image), it's wider.
You'll get the image without the black "padding" on the side if you use wrap_content for the height as well.
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="0pt"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:src="#drawable/list_download"
android:background="#android:color/black"
android:padding="0pt"/>
So, if you want the picture to be a specific size, you could resize it in your drawable folder to the size you want.
you just need use android:scaleType="fitXY" and set padding 0dp.
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:padding="0dp"/>
you can put it in a Frame like so :
<FrameLayout
android:layout_width="wrap_content"
android:background="#android:color/black"
android:layout_height="wrap_content">
<ImageView
android:src="#drawable/list_download"
android:scaleType="fitCenter"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_width="8dp"/>
</FrameLayout>
it will be much easier to play with it like so

How to scale and align an image in an imageView

So to align an imageView with layout_gravity I must use wrap_content
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="#drawable/heart">
</ImageView>
But If I want to scale the image in the view, I can't use layout_gravity because I need to define layout_width and layout_height.
How can I scale and use layout_gravity?
edit: I answered my own question with this solution
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right">
<ImageView
android:layout_width="10dp"
android:layout_height="10dp"
android:background="#drawable/heart">
</ImageView>
</LinearLayout>
Use this in your image view
android:scaleType="center"
and for more types of scaleType see here
ImageView is comes with different configuration options to support
different scaleTypes. scaleType options are used for scaling the
bounds of an image to the bounds of this view.
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/heart"
android:scaleType="center"
android:adjustViewBounds="true">
</ImageView>
http://developer.android.com/intl/es/reference/android/widget/ImageView.ScaleType.html
When you use wrap_content, your ImageView takes the size of the image. The layout_gravity won't change by changing the imageView size. use android:scaleType="fitEnd" for changing the image alignment
I answered my own question. I had to nest the image view inside a parent layout, using gravity not layout_gravity
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right">
<ImageView
android:layout_width="10dp"
android:layout_height="10dp"
android:background="#drawable/heart">
</ImageView>
</LinearLayout>
No, you don't have to use wrap_content even if you set layout_gravity.
layout_gravity only works when I set the height and width to wrap content
Try to set the parent ViewGroup's width to match_parent to expand it full width.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_gravity="right"
android:background="#drawable/heart" />
</FramaLayout>

Re sizing an image in imageView

I want to define maxHeight for an image that it's adjustViewBounds has been set to true.
in this way adt automatically keeps aspect ratio.
is there any way to gain this approach without keeping aspect ratio?
this is the image, and i want to stretch it from sides, without being displaced:
You can do like this
<ImageView
android:layout_width="100dp"
android:layout_height="400dp"
android:src="#drawable/ic_launcher"
android:scaleType="fitXY"/>
try this
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/your image name"
android:scaleType="fitXY"/>
I think android:scaleType="fitXY" is what you are looking for.

Remove white border around an ImageView

My designer keeps adding a little padding around my image.
I want the image the stick on the top and to fill out the width of the screen.
Here's a screenshot from the designer:
This is my XML code:
<ImageView
android:id="#+id/markertap_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/header_bootsverleih_xhdpi" />
It looks like the image is larger than the screen width, so it's getting scaled down after sizing. Try adding android:adjustViewBounds="true" to your ImageView.
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:id="#+id/imageView"
android:cropToPadding="false"
android:scaleType="fitXY" />
Experienced the same when I used an ImageView for Splashscreen, this^ worked for me.
you might want to add it your image view only this.
It fixed my problem.
android:paddingVertical="0dp"
android:paddingHorizontal="0dp"

Categories

Resources