Why are my images compressed? - android

I'm using layout xml file for the UI. But the images are compressed and the qualities have lost in some level.
My code is like this:
<ImageView
android:layout_width="480px"
android:layout_height="717px"
android:layout_x="0px"
android:layout_y="45px"
android:scaleType="fitXY"
android:src="#drawable/e4" />
The drawable is actually 480x717.
What's the problem here? Is it due to the fitXY?

Of course it is.
You say you want some dimensions, but then you say you want to scale it.
So it scales it.

Related

Android Studio and PNG vector images

Creating vector images in Photoshop (for transparent backgrounds). When I add them as the image source for my ImageButtons, and run the app, the image displays with a white background.
Can't find any useful info on why the images are not coming out transparent through the app.
Are there some additional steps/coding required to make vector images work properly? I can't see why.
Example code, as requested:
<ImageButton
android:id="#+id/btnGameUp"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="#drawable/arrowright"
android:adjustViewBounds="false"
android:clickable="true"
android:cropToPadding="false"
android:padding="0dp"
android:scaleType="fitXY"
android:layout_marginLeft="270dp"
android:layout_marginTop="260dp" />
No one came to help us, but we managed to find the solution on our own after hours of crying and holding each other for comfort.
In the layout xml file, you need to add the following line to each vector object:
android:background="#android:color/transparent"
That's it! Tested and working perfectly. Hope this helps someone.

Android - ImageView does not display image. Nor does setImageResource()

I use an ImageView control as shown:
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:id="#+id/imgHangMan"
android:src="#drawable/hang0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
The above code displays the image in the Graphical Layout preview of the xml file. But on launching the app, I see no image. Also, changing the image using
imgHangMan = (ImageView)findViewById(R.id.imgHangMan);
imgHangMan.setImageResource(R.drawable.hang1);
This piece of code also does not work either. The image files are in .gif format and are in the drawable folder.
Any pointers ?
Natively ImageView doesnot support animated image. You have two options to show animated gif file
1) Use VideoView 2) Use ImageView. But Split the gif file into several parts and then apply animation to it.
Try this link-playing-gif-animation you will get the desired result.
Try this
image.setImageDrawable(getResources().getDrawable(R.drawable.hang1));
User this :
http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html
Go by this.

TextView Background Resource

I implemented the following TextView in a RelativeView:
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#drawable/bg"/>
The problem is that the size will be set dynamically to 15% of the screen while the application is running. But when I do this the background ressource doesn't get the size of the TextView. It has the original size of 150x150 px. What can I do to avoid this?
(I don't want to take a smaller ressource because it doesn't look well then)
Try using another scaleType, for example android:scaleType="fitXY".
Also you can try making a nine-patch image. To do this, go to your Android SDK folder - tools - draw9patch application. Then you will have options to open your image and then save it as nine-patch image. Reference it as usual in your layout.

Avoid image scaling in ImageView

I am using an Image view with these XML attributes
<ImageView
android:id="#+id/widget_list_bitmap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
android:scaleType="center"
android:src="#drawable/place_holder" >
</ImageView>
and at runtime I create a let's say 400x400 bitmap, save it to a file and set the ImageView src using a file URI
remoteViews.setUri(R.id.widget_list_bitmap, "setImageURI", myFileUri);
(this is to avoid RemoteViews issues with large bitmaps).
Everything works fine except that the displayed image is scaled down and is smaller than 400x400, more like 250 x 250 (possibly 400/density, density = 1.5).
Is there a way to force an ImageView to really not scaling images it fetches from URI?
You could manually download it and when you load it with BitmapFactory set inScaled to false. Then you would use setImageViewBitmap instead of setUri or setImageViewUri.
Update:
Unfortunately I don't really see a way around this using setUri. An alternative to using setUri to get around the 1MB limit is to use setImageViewBitmap but slice up the bitmap and display it on multiple views, maybe a 2x2 or 3x3 grid of ImageViews or something like that. You'd have to split it into multiple updates using partiallyUpdateAppWidget, but I think it should work. The hitch is that this requires API 11.

Why android resizes image?

I'm trying to change my application data source to the sdcard so that it doesn't take too much internal memory.
However, I had an Image that was dynamically loaded from the resource and displayed in an ImageView, now I load the image from the sdcard whenever I need it.
I had been using imageBox.setImageResource(imageID) and I changed to imageBox.setImageDrawable(imageDrawable).
The problem is that now Android resizes my image and it doesn't fit where it should.
Why is it resizing the image this way? And how can I stop it?
Thanks in advance :)
Add the tag android:scaleType="fitXY" to your ImageView's layout XML.
Ex.
<ImageView
... several settings ...
android:scaleType="fitXY"/>
Edit:
If your image is simply too big to fit inside the ImageView - it will have to do some kind of scaling. There are some other options as described in the API:
http://developer.android.com/reference/android/widget/ImageView.ScaleType.html
Try the following for ImageView:
android:layout_height="fill_parent"
android:layout_width="fill_parent"
No Scale Type.
The ImageView Should be within Fixed Size (in dp) Parent View.

Categories

Resources