0

I wanted a picture background. When I set the background property of the root element to the picture, it was distorted due to aspect ratio difference. After reading StackOverflow answers, I changed it to,

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:src="@drawable/wallpaper1"/>

The image is a 300KB full HD image. It looks good, but the problem is that when I start the activity, there is a stutter and a warning message.

I/Choreographer: Skipped 38 frames!  The application may be doing too much work on its main thread.

When I removed the ImageView, there was no such problem. Should I not use 'src' in the layout XML, and load the image on my own using a background thread?

Damn Vegetables
  • 11,484
  • 13
  • 80
  • 135
  • Have you read this ? https://stackoverflow.com/questions/14678593/the-application-may-be-doing-too-much-work-on-its-main-thread – John Joe Dec 22 '17 at 15:19
  • I know what it means, but the point is that imageview.src is not my code. It is in a layout XML that is loaded by the Android framework. So I was wondering if there already is an in-built solution for this kind of thing in the framework, or I should not use 'src' and load the image on my own. – Damn Vegetables Dec 22 '17 at 15:23

1 Answers1

0

Try to convert image in to .webp format to reduce image size, and use lossless encoding type to keep image quality.

In Android Studio

1. right click on image asset

2. click Convert to WebP

3. Choose use lossless encoding and tap (API 18+)

Robert Apikyan
  • 1,972
  • 1
  • 20
  • 23