Android Images scaling - android

I always have problems when using images. I want to use an image as splash screen. So I imported all resolutions (ldpi to xxhdpi) of my image using Multisource-Drawable in Android Studio. Then, I created a imageview in my Activity and set Width and Height to 150dp both. It seems to use the ldpi resource and the image get very blurry.
What's the best way to import images in Android Studio to general use?
[UPDATE]
Android is chosing the right size, but not how I want. I fixed it by adding a 512x512 png file and then setting its Width And Height to 150dp

I think your question may have two separate answers. First, you are assuming that an image is the best way to set up a splash screen. This is not so, as the content would have to be called after the app has already finished setting up. That would mean your user sees a flash (or more) of a blank screen before the splash screen is shown. Second, you would like to know the best way to import images into Android Studio. Here are the two different answers:
#1 The best way to implement a splash screen is to have a theme called on a blank activity. The theme would include your desired image and background color. The reason for this is to eliminate the short break before content is called. Click here for a link describing more and giving a tutorial.
#2 In my opinion, the simplest and most robust way to add an image resource is to use the Image Asset import feature. Follow these steps:
Right click on "res" (in the Project View) -> New -> Image Asset
On Icon Type choose Action Bar
and Tab Icons
For Asset Type choose Image
Choose the image path (on your computer)
Give your image a name (no UPPERCASE, only lowercase and underscores, etc)
Next -> Finish

make image view height and width wrap_content and set its gravity to center..

Related

Background image appear to be small in android app?

I have a little problem, if someone could tell why:
1. My background image in my toolbar's button appear really small ?
2. When I import some images, it show a blank image in the xxhdpi, xhdpi, hdpi, mdpi thumbnails.
Screenshot:
Android Studio screenshot
Thank's in advance!
A <Button> is primarily meant to display text, though it does also allow you to display images. However, it allows you to display images above, below, to the left of, or to the right of the text. That is why you were able to get an image using android:drawableTop... this is the image to display above your text.
Probably you just want to use <ImageView> here instead, and specify your image using the android:src attribute.
Another solution would be to populate your toolbar using a menu instead of manually adding views, but perhaps that's not possible for your requirements.
Instead of Button, You can use ImageButton in this case and you can give android:src="[your icon]"
Note :
Try to give min 48dp width and height to button

Is it better to rotate an arrow-icon or to use separate icons for right and left arrow?

In Android, i have an Arrow-Right icon (SVG). I also need an Arrow-Left icon. Is it better to use Arrow-Right and rotate it by 180° or use a separate drawable?
I imagine that rotating one icon is more efficient than loading a second drawable, but what if i have to use the icon hundreds of times in my activity?
Also, what if i have to use a bigger image (a .png file > 1MB)?
I'm guessing, if it's really an icon, it'll be small. So small that I probably would just add the rotated version. If you were to rotate it programmatically, you could cache it, of course. If you were worried about the size of your app, you could rotate the image and save it into the app's disk cache so that you don't have to do each time. At least I'd avoid having to rotate the image hundreds of times in the activity (or app).
If you need icons for the menu or the action bar there is no place to rotate it, you just assign a drawable resource ID to the menu item.
The standard (correct) way is to generate PNG's for each screen density and in your case for each orientation.
http://iconhandbook.co.uk/reference/chart/android/

Is it possible to resize images within your Android app in real time?

I am going to have this activity that will have these "bubbles", which I will add to my app as a drawable resource. Depending on the value associated with each bubble, I want to increase or decrease in size so they look bigger or smaller compared to others. I've tried the following, which didn't work:
RelativeLayout.LayoutParams transportParams = new RelativeLayout.LayoutParams(t, t);
mTransportationBubble.setLayoutParams(params);
This code actually does resize the images, but it moves them all to the top left corner of my screen and stacks them on top of each other. Any idea how I could do that?
I am going to have this activity that will have these "bubbles", which I will add to my app as a mipmap resource.
Put your images into hdpi folder and try again. The mipmap folder is reserved for launcher icons.
check this doc for more information about resource folders

nine patch image shows dots

I've created several 9-patch images using the android draw9patch utility and I've yet to make one that works. On one image I've got 2 dots on the top edge, and 2 dots on the left edge; the 'show bad patches' button shows no bad patches, and the samples on the right side look fine. However, in the app the image appears with the black 9patch dots showing on the top and right sides.
Are we suppose to set the backgroundColor or cachecolor to hide the dots in the imageview?
I'm targeting google maps 2.3.3. Could there be known issues with this API?
What is the full name that you gave to the file? The file name must end in ".9.png" to work properly. Otherwise it will be treated as a normal png file which would display the dots and lines at the edges of the image.
Those dots will go away when they're displayed on the phone. They tell the Android System what parts of the image can be stretched without warping how it's supposed to look. If you notice the format of the 9patch is .9.png, there's preprocessing that Android does before the image is displayed and the dots are removed. 'Show Bad Patches' rarely makes a difference I've found, even if they're considered 'bad' they work how I want them too. At least in my experiences. Just add the 9patches to your activity and reference them as you normally would
Update
Wait a second. Are you trying to use 9patches as images to be displayed in an ImageView? That's not what 9patches are for. 9patches are stretchable images for buttons or other UI elements (i.e. for different screen sizes) so developers can have one image to stretch and fit the different sized buttons instead of one for each size. Android displays most image formats in ImageView. If you're displaying the 9patches with an ImageView, Android isn't preprocessing the black dots as slices of that image that are repeatable, it's just displaying the whole thing.

Screen Size Resolution problem

I have Some Background image in to My Application. That background Image also contain the Button image. I am manualy create and set the Button on that Button image of the Background Image. now while the Screeen size changes for another device then the real button and the Button Image that show on the Background image shows different. How i can set it for the ProperView. Or if i want to make another Background Image that dont contain the Image of the Button. Then which Screen size should i have to prefer for different Device Competibility.
I have read this competibility documents. But not getting proper idea if i have to set the background image for all device then which screen size i have to prefer. So can any budy explain me in Short and Sweet ?
Thanks.
According to Supporting Multiple Screens, you have to create multiple layout folders!
For example: you can have 2 versions of my_layout.xml
res/layout-xlarge/my_layout.xml
res/layout-normal/my_layout.xml
Read Supporting Multiple Screens; There are lots of details there.
Read Supporting Multiple Screens; There are lots of details there.

Categories

Resources