1

I am developing an application in Android Studio. I've applied an image as the background of the activity and everything looks fine in the layout editor. No image distortion. However, when I run the emulator for Nexus 5X phone, the background image gets distorted profoundly. Why?

The image that I use for the background is stored inside the drawable folder and is referenced in the following way inside the XML file defining the style of the problematic activity: android:background="@drawable/login_activity_background"

I've looked up Nexus 5X phone resolution for backgrounds and found that images have to be 1080x1920 pixels and my background picture fits this resolution pixel-perfect (this is, my background image is also 1080x1920 pixels), so I guess that image resolution doesn't have to do with my problem?

Here is an image of my problem:enter image description here

AnimaVivens
  • 399
  • 3
  • 11
  • What type of image is it, is it a JPEG or have lossy compression? I suggest you use a shape and gradient (XML) rather than an image, it will be smoother, a lot more efficient and consistent across Android devices. I'm not 100% sure of the emulator colour depth though. – Mark Oct 09 '18 at 21:54
  • It is a PNG image, non-compressed I am sure. But does the shape act the same way as the background if I stretch it across the entire activity screen? Will I still be able to add other components above this shape? – AnimaVivens Oct 09 '18 at 21:57
  • Yes - see this question, and answers https://stackoverflow.com/questions/5976805/android-linearlayout-gradient-background - or Google it, it is very easy to create. This is a personal suggestion, the answer below will give good insight into why you are experiencing the current problem (as I hinted in my first comment), I have suggested an alternative which is a better approach IMHO for creating gradients in Android. – Mark Oct 09 '18 at 21:59
  • Thank you sir, will make sure to take a good look into it! – AnimaVivens Oct 09 '18 at 22:03
  • @MarkKeen I've updated my application in accordance with your directions, but the problem still persists :( – AnimaVivens Oct 10 '18 at 20:48
  • Then this confirms it's just an emulator rendering issue only. – Mark Oct 10 '18 at 21:27
  • Yep, I agree. Running it from hardware device works normally. – AnimaVivens Oct 10 '18 at 22:09

1 Answers1

0

It's because of how the emulator screen is rendered.

It's not distorted. Your computer either isn't powerful enough to render full color in an emulator, or the color space is limited for other reasons.

Try on a real device and you shouldn't have this issue.

TheWanderer
  • 16,775
  • 6
  • 49
  • 63