Aarushi
Aarushi

Reputation: 3

ImageView is not displaying the image src

I am trying to use the Icon image provided in the drawable folder using imageView and src attribute but the icon is not being displayed when I run the app and even it's not showing in the emulator.

<RelativeLayout
       android:layout_width="match_parent"
       android:layout_height="wrap_content">
       <ImageView
           android:layout_width="60dp"
           android:layout_height="60dp"
           android:scaleType="center"
           android:adjustViewBounds="true"
           android:src="@drawable/icon-chat"/>
</RelativeLayout>

I expect the image should be displayed in the imageview. Do I need to add any other attributes in the imageView ???

Upvotes: 0

Views: 171

Answers (4)

Vibhanshu Sharma
Vibhanshu Sharma

Reputation: 259

There is certain naming convention in naming the drawables file, so while naming your files in drawable keep in mind following two points .

1)Valid characters for naming resources is [a-z, _, 0–9] .In short all small case characters, numbers, and underscore.

2)First letter of your asset(file) name can be either _ or a small case character, it cannot be a number.

Upvotes: 1

Pradeep
Pradeep

Reputation: 236

Your icon may be of larger size. Copy it to folder drawable-xxhdpi in project explorer then try.

Upvotes: 0

Muntasir Aonik
Muntasir Aonik

Reputation: 1957

Use drawable-nodpi folder in res if image is too big.

Upvotes: 0

Ali Kazal
Ali Kazal

Reputation: 61

You can't have a '-' in a drawable name. Rename your drawable to 'icon_chat' instead of 'icon-chat'.

<ImageView
     android:layout_width="60dp"
     android:layout_height="60dp"
     android:scaleType="center"
     android:adjustViewBounds="true"
     android:src="@drawable/icon_chat"/>

Upvotes: 0

Related Questions