Android布局XML中的app:srcCompat和android:src之间的区别 [英] Difference between app:srcCompat and android:src in Android's layout XML
问题描述
每当我使用Android Studio的Vector Assets创建带有图标的ImageView时,在app:srcCompat="@drawable/ic_play"
Whenever I create an ImageView with icon added using Android Studio's Vector Assets, I'm getting an error at the line app:srcCompat="@drawable/ic_play"
当我用android:src
更改app:srcCompat
时,错误消失了,但是图标看起来像是像素化的.
When I change the app:srcCompat
with android:src
, the error is gone but the icon looks pixelated.
app:srcCompat="@drawable/ic_play"
和
android:src="@drawable/ic_play"
推荐答案
app:srcCompat
是集成 vector drawables .矢量可绘制对象可让您用XML中定义的单个矢量图形替换多个png资产.虽然以前只限于棒棒糖和更高版本的设备
is the most foolproof method of integrating vector drawables into your app.Vector drawables allow you to replace multiple png assets with a single vector graphic, defined in XML. While previously limited to Lollipop and higher devices
注意
截至 Android支持库23.3.0 >, 支持向量可绘制对象 只能通过 app:srcCompat
加载.
As of Android Support Library 23.3.0, support vector drawables can only be loaded via app:srcCompat
.
您需要将 vectorDrawables.useSupportLibrary = true 添加到您的build.gradle
文件
you need to add vectorDrawables.useSupportLibrary = true to your build.gradle
file
// Gradle Plugin 2.0+
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
android:src
设置一个可绘制对象作为此ImageView的内容,它将显示在 它的原始大小.没有自动缩放.
Sets a drawable as the content of this ImageView.It will display in its original size. No automatic scaling .
这篇关于Android布局XML中的app:srcCompat和android:src之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!