Adjusting images on different screens

2

I'm running the app on two emulators that have exactly the same resolution but different densities:

  • 720 x 1280 160dpi
  • 720 x 1280 320dpi
  • I want the image to take the same space on the screen. I understand that, using DP, the density becomes indifferent, because the system calculates the amount of pixels according to the density and the space that the image must have on the screen. However, this does not happen:

    HowdoIgetthisvalueinDPsothatanimagetakesexactlythesamespaceonscreenswithdifferentsizesanddensities?

    XML:

    <RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/rl"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
    
        <ImageView
            android:id="@+id/logo"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:src="@drawable/logo"
            android:layout_centerInParent="true"/>
    </RelativeLayout>
    
        
    asked by anonymous 10.07.2016 / 14:06

    1 answer

    2

    Create images with different resolutions and place them in the respective packages, according to the list below:

    • xlarge (xhdpi): 640x960 (320 dpi)
    • large (hdpi): 480x800 (240 dpi)
    • medium (mdpi): 320x480 (160 dpi)
    • small (ldpi): 240x320 (120 dpi)

    documentation link

        
    10.07.2016 / 18:14