How to make an image if to adjust to various screen sizes on Android?

0

I am using a button with background image

                   <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:id="@+id/btn"
                    android:background="@drawable/myimage" />

I wanted this image to fit several screen sizes, for example, would I have to do equal to unity where canvas is created and everything in canvas will automatically adjust from of resolution passed by reference?

    
asked by anonymous 22.02.2016 / 02:30

3 answers

1

If you're using Android Studio to build your app, replace android:background="@drawable/myimage" />

by

android:background="@mipmap/myimage" />

This mipmap folder in Android Studio maps to multiple folders in your project file system.

Where you saved the image in drawable , you will have to save the image in mipmap :

orsavedirecttoyourapp'sfolder:

Do one of these two steps, and Android will automatically adjust your image.

    
19.05.2016 / 15:06
0

Create a photo with the same name for each resolution. create a folder inside the drawable folder for each resolution (name the folders: hdpi or ldpi or mdpi or xhdpi or xxhdpi). put the photos inside those folders - which are already in drawawable. the android will take care of changing at the time of the execution according to the model of the cellular.

    
22.02.2016 / 21:20
0

I think you may be looking for the imageview scaleType attribute, it is possible to see how the image will behave within the boundary of the canvas itself, whether it will be cut or not.

If this is the case and you can not use the imageview compiler instead of your button, you can generate a drawable with the lib glide and set it as the background on your button.

Glide is a famous lib for handling and caching images on android. there are also some auxiliary libs for it, such as Glide transformations that allows you to apply a series of transformations to any image.

link

link

    
26.02.2016 / 04:28