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 trialcodeoverload
24,260 PointsIs there a difference between android:src and app:srcCompat?
When should I use one over the other for an ImageView
?
1 Answer
Kyle Baker
8,211 PointsFrom 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
24,260 Pointscodeoverload
24,260 PointsMakes 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
8,211 PointsKyle Baker
8,211 PointsNp and thanks for sharing the bit about being able to use pngs with it