1

I have made an XML file which has 3 images . Firstly I am not clear about why the image size is different on different screen sizes even when i am using "dp" for the dimensions of the image . So Next what i did is ,I made different layout files for different screen sizes . There also the problem i see is that most of the screens from 3.5inches to 5 inches are handled by the normal\something.xml. And the image size that appears in 3.5" screen is different from 5" screen.

Here Is the XML file normal\something.xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#add8e6"
android:orientation="vertical"
android:id="@+id/mood">

<TextView
    android:layout_width="match_parent"
    android:layout_height="15dp"
    />


<TextView android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="#000000"
    android:textSize="33sp"
    android:text="How's your Mood ?"
    android:gravity="center_horizontal"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="30dp"
    />
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_marginTop="15dp"
    >


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3"
        android:orientation="horizontal"
        android:id="@+id/happyLayout"
        android:background="#85a9b4">

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:id="@+id/happyRadio"
            android:textSize="30sp"
            />
        <ImageView
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:src="@drawable/happy"
            android:layout_marginLeft="30dp"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3"
        android:orientation="horizontal"
        android:id="@+id/sickLayout">

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:id="@+id/sickRadio"/>
        <ImageView
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:src="@drawable/sick"
            android:layout_marginLeft="30dp"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3"
        android:orientation="horizontal"
        android:id="@+id/sadLayout">

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="30dp"
            android:id="@+id/sadRadio"/>
        <ImageView
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:src="@drawable/sad"
            android:layout_marginLeft="30dp"/>
    </LinearLayout>




    <Button
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2"
        android:background="#f4880d"
        android:text="ADD MOOD"
        android:textColor="#ffffff"
        android:textSize="30sp"/>

</LinearLayout>

The above file is for Normal Screen sizes. For Large and small screens am simply changing the dimensions of the image to lower or higher "dp" value (please correct me if this approach is not correct).

Would be great if you can suggest the approach i should follow to handle image sizes for different screen size and density.

  • Have added the images according to density , i.e mdpi,hdpi or xhdpi ? – Vikrant Sep 27 '16 at 05:24
  • Based on the screen size place the images in different density folder i.e, drawable(mdpi),drawable(hdpi),drawable(xhdpi). and the density is like this mdpi(1.0 Baseline), hdpi(1.5), xhdpi(2.0) – Kishor N R Sep 27 '16 at 05:34
  • So if i use different size images like you have said , then different images will be used for screen size 3.7 and 5.7" ? Am asking because both of these screen sizes are considered as normal in the Android Dev Tool and same layout file normal/something.xml is used by both of these screen sizes. – Deepanshu Batra Sep 27 '16 at 06:53
  • For info on different densities of Android devices. Click here- https://stackoverflow.com/a/44924525/4082923 – Gurvinder Singh Jul 05 '17 at 11:13

1 Answers1

1

Use some tool like this where you can generate images for all screens. Also refer official docs for more help.

For Images put your images accordingly

res/drawable-mdpi/graphic.png         // bitmap for medium-density
res/drawable-ldpi/graphic.png         // bitmap for large-density
res/drawable-hdpi/graphic.png         // bitmap for high-density
res/drawable-xhdpi/graphic.png        // bitmap for extra-high-density
res/drawable-xxhdpi/graphic.png       // bitmap for extra-extra-high-density

Also keep in mind

xlarge screens are at least 960dp x 720dp
large screens are at least 640dp x 480dp
normal screens are at least 470dp x 320dp
small screens are at least 426dp x 320dp
Nikhil
  • 3,711
  • 8
  • 32
  • 43
  • I Tried this. The screen size 3.7" and 5.7" are taking the same image i.e the medium density . And the same image looks good on one device but not on the other. Can you please suggest something ? – Deepanshu Batra Sep 27 '16 at 07:37