Full screen background image in an activity

There are several ways you can do it. Option 1: Create different perfect images for different dpi and place them in related drawable folder. Then set android:background=”https://stackoverflow.com/questions/16135984/@drawable/your_image” Option 2: Add a single large image. Use FrameLayout. As a first child add an ImageView. Set the following in your ImageView. android:src=”https://stackoverflow.com/questions/16135984/@drawable/your_image” android:scaleType = “centerCrop”

What’s the difference between CENTER_INSIDE and FIT_CENTER scale types?

Here’s a graphical illustration of the difference between CENTER_INSIDE and FIT_CENTER. Image used (100 × 100): Small image view (75 × 50): CENTER_INSIDE: FIT_CENTER: Both CENTER_INSIDE and FIT_CENTER shrink the image. Large image view (300 × 200): CENTER_INSIDE: FIT_CENTER: CENTER_INSIDE does not enlarge the image, FIT_CENTER does. The Android robot is reproduced or modified from … Read more

Adding gif image in an ImageView in android

In your build.gradle(Module:app), add android-gif-drawable as a dependency by adding the following code: allprojects { repositories { mavenCentral() } } dependencies { compile ‘pl.droidsonroids.gif:android-gif-drawable:1.2.+’ } UPDATE: As of Android Gradle Plugin 3.0.0, the new command for compiling is implementation, so the above line might have to be changed to: dependencies { implementation ‘pl.droidsonroids.gif:android-gif-drawable:1.2.17’ } Then … Read more

Fit image into ImageView, keep aspect ratio and then resize ImageView to image dimensions?

May not be answer for this specific question, but if someone is, like me, searching for answer how to fit image in ImageView with bounded size (for example, maxWidth) while preserving Aspect Ratio and then get rid of excessive space occupied by ImageView, then the simplest solution is to use the following properties in XML: … Read more

How to set margin of ImageView using code, not xml

android.view.ViewGroup.MarginLayoutParams has a method setMargins(left, top, right, bottom). Direct subclasses are: FrameLayout.LayoutParams, LinearLayout.LayoutParams and RelativeLayout.LayoutParams. Using e.g. LinearLayout: LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); lp.setMargins(left, top, right, bottom); imageView.setLayoutParams(lp); MarginLayoutParams This sets the margins in pixels. To scale it use context.getResources().getDisplayMetrics().density DisplayMetrics