Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Weather App (2015) Building the Weather UI Adding the Upper Half

codeoverload
codeoverload
24,260 Points

Is there a difference between android:src and app:srcCompat?

When should I use one over the other for an ImageView?

1 Answer

Kyle Baker
Kyle Baker
8,211 Points

From what I've gathered, seems the difference is that app:srcCompat is an attribute used when you want a vector drawable (vector images can be resized without losing image quality where png files lose image quality). Android:src would be the attribute for you if you were to go with a png drawable. You can use these attributes on ImageButtons and ImageViews (maybe more, but at least those two).

I used this link if you want to check it out http://android-developers.blogspot.com/2016/02/android-support-library-232.html

codeoverload
codeoverload
24,260 Points

Makes sense, but I used a png file and Android Studio automatically chose app:srcCompat...strange. I looked again on some other sites and here (https://medium.com/@chrisbanes/appcompat-v23-2-age-of-the-vectors-91cbafa87c88#.pf6wmj3oz) it says (as you said) that srcCompat was introduced because of vector graphics. Maybe you can still use it for pngs but it provides some new functionality for vectors.

Thanks for your answer anyway!

Kyle Baker
Kyle Baker
8,211 Points

Np and thanks for sharing the bit about being able to use pngs with it