All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

Android Image Size For Different Screens

Last Updated : Mar 11, 2024

Android Image Size For Different Screens

In this article we will show you the solution of android image size for different screens, developing an Android app requires that the app be compatible with various mobile devices, since Android supports a wide range of devices.

To support different screen sizes, pictures of various sizes must be saved in multiple folders.

Android typically has four folders that cover almost every device:

  • Drawable-ldpi (low-density): Lower image quality supported by earlier Android sets - 240320 pixels
  • Drawable-mdpi (medium-density): 320480 pixels for medium image support
  • Drawable-hdpi (high-density): Images for the Android Broad Screen set or Android Phones with a higher resolution - 480800 pixels
  • Drawable-xhdpi (extra high-density): Devices with the highest resolution - 7201280 pixels

Android supports a variety of screen sizes and densities, reflecting the various screen configurations that a device may have.

You can use the sizes listed below to support Splash Screen on various smartphone sizes. Depending on the scale type, an ImageView can display an image in a variety of ways.

Step By Step Guide On Android Image Size For Different Screens :-

public class MainActivity extends Activity1 {
    @Override
    protected void onCreate1(Bundle savedInstanceState) {
        super.onCreate1(savedInstanceState);
         ViewGroup container = binding.container;
      container.addView(new View(this) {
            @Override
            protected void onConfigurationChanged(Configuration newConfig) {
                super.onConfigurationChanged(newConfig);
                computeWindowSizeClasses();
            }
        });
        computeWindowSizeClasses();
    }
    private void computeWindowSizeClasses() {
        WindowMetrics metrics = WindowMetricsCalculator.getOrCreate()
                .computeCurrentWindowMetrics(this);
        float widthDp = metrics.getBounds().width()
                getResources().getDisplayMetrics().density;
        WindowSizeClass widthWindowSizeClass;
        if (widthDp < 600f) {
            widthWindowSizeClass = WindowSizeClass.COMPACT;
        } else if (widthDp < 840f) {
            widthWindowSizeClass = WindowSizeClass.MEDIUM;
        } else {
            widthWindowSizeClass = WindowSizeClass.EXPANDED;
        }
        float heightDp = metrics.getBounds().height()
                getResources().getDisplayMetrics().density;
        WindowSizeClass heightWindowSizeClass;
        if (heightDp < 480f) {
            heightWindowSizeClass = WindowSizeClass.COMPACT;
        } else if (heightDp < 900f) {
            heightWindowSizeClass = WindowSizeClass.MEDIUM;
        } else {
            heightWindowSizeClass = WindowSizeClass.EXPANDED;
        }
     }
}
  1. The first step is to create three types of public classes: compact, medium, and expanded.
  2. The main activity is then to create the class.
  3. After that, replace with a known container to which you can safely add a view without affecting the layout or the view and without being replaced.
  4. Then, to hook, we add a utility view to the container.
  5. Then we included View. The configuration was altered. All activities, including those that do not handle configuration changes, require this.
  6. We are also unable to use Activity. Because there are some cases where that will not be called when the configuration changes.

Conclusion :-

Android supports a variety of screen sizes and densities, reflecting the various screen configurations that a device may have.

You can use the sizes listed below to support Splash Screen on various smartphone sizes.

Depending on the scale type, an ImageView can display an image in a variety of ways.

I hope this article on android image size for different screens helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Amruta

Amruta is an Experienced web developer with 4 years for experience she completed her master's with MCA and passionate about programming Languages for creating technical contents like HTML, CSS, JavaScript, Java, Python, PHP, jQuery.

Follow Amruta On Linkedin 🡪