Different picture display in real device and emulator Android

Different picture display in real device and emulator Android, I do not understand what is the reason

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity"
android:orientation="vertical">

<ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:src="@drawable/music"
        android:contentDescription="@string/app_name"
        android:layout_weight="0.5"
    android:cropToPadding="false" />

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="0.9">

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="1"
        android:id="@+id/button" />

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="2"
        android:id="@+id/button2" />

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="3"
        android:id="@+id/button3" />
</LinearLayout>

and here is how it looks on an emulator and a real device

Emulator Real device

I enclose code Layout. I will be glad of any help

Upvotes: 2

Views: 173

Answers (2)

Charaf Eddine Mechalikh
Charaf Eddine Mechalikh

Reputation: 1248

first your picture height and width are set to wrap_content , try this ,but you need a high resolution picture , see Harsh Dattani's answer about picture sizes and your problem should be solved

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity"
android:orientation="vertical">

<ImageView
    android:layout_width="fill_parent"<!--changed this-->
    android:layout_height="fill_parent"<!--changed this-->
    android:id="@+id/imageView"
    android:src="@drawable/music"
    android:scaleType="centerCrop"<!--added this line-->
    android:contentDescription="@string/app_name"
    android:layout_weight="0.5"
    android:cropToPadding="false"
    android:layout_gravity="center_horizontal" />

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="0.9">

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="1"
        android:id="@+id/button" />

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="2"
        android:id="@+id/button2" />

    <Button
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="3"
        android:id="@+id/button3" />
</LinearLayout>
</LinearLayout>

Upvotes: 1

Harsh Dattani
Harsh Dattani

Reputation: 2129

Maintaining density independence is important because, without it, a UI element (such as a button) appears physically larger on a low-density screen and smaller on a high-density screen. Such density-related size changes can cause problems in your application layout and usability.

As perfectly documented in Supporting Multiple Screens docs, you need to support multiple screen size devices. There will be separate Drawable folders targeting various densities, place your image with specific density in respective folder.

A set of six generalized densities:

  1. ldpi (low) ~120dpi

  2. mdpi (medium) ~160dpi

  3. hdpi (high) ~240dpi

  4. xhdpi (extra-high) ~320dpi

  5. xxhdpi (extra-extra-high) ~480dpi

  6. xxxhdpi (extra-extra-extra-high) ~640dpi

Upvotes: 0

Related Questions