0

I want show image in ImageView, but don't show it. I use XML code and Java code but don't show. show in simulator but in real devices don't show.
tested on LG G2, HTC One X, Samsung Galaxy S3.

my xml code :

    <ImageView
    android:id="@+id/sms_dialog_header"
    android:layout_width="fill_parent"
    android:layout_height="150dp"
    android:layout_alignParentTop="true"
    android:scaleType="centerCrop"
    android:background="@drawable/show_sms_header" />

my java code :

        Dialog_Header_Img = (ImageView) findViewById(R.id.sms_dialog_header);
    Dialog_Header_Img.setImageResource(R.drawable.show_sms_header);

I used to be separated from each.

Please tell me the solution

Mohammad
  • 91
  • 1
  • 1
  • 9

2 Answers2

1

First of all you should set image in xml by code:

android:src="@drawable/show_sms_header"

not by android:background, well you can set background to color or other image but your main image you should set by android:src

If you changing something about your image, leave first line in your code that you show, and delete second, if setting image is only thing you set, then you can delete both, because you set source of image in xml.

miljon
  • 2,021
  • 1
  • 12
  • 18
  • Like others guys are saying, try optimize your image. By create a few images in different drawable folder or change resolution of image pragmatically, for example like there: http://stackoverflow.com/questions/4837715/how-to-resize-a-bitmap-in-android – miljon Mar 09 '15 at 14:52
0

The "src" attribute should be set to your drawable if you want it to be "centerCrop" correctly.

Check this out :

 <ImageView
    android:id="@+id/sms_dialog_header"
    android:layout_width="fill_parent"
    android:layout_height="150dp"
    android:layout_alignParentTop="true"
    android:scaleType="centerCrop"
    android:src="@drawable/show_sms_header" />

Make sure that your file, called "show_sms_header", is in your drawable ( /res/drawable) directory.

GuillaumeAgis
  • 3,535
  • 1
  • 18
  • 24