q12*_*26y 5 android android-appcompat imageview xml-drawable
绘制/ information.xml
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M13,9H11V7H13M13,17H11V11H13M12,2A10,10 0,0 0,2 12A10,10 0,0 0,12 22A10,10 0,0 0,22 12A10,10 0,0 0,12 2Z"/>
</vector>
Run Code Online (Sandbox Code Playgroud)
LayoutofCardView.xml
<ImageView
android:layout_width="24dp"
android:background="#f00"
android:layout_height="24dp"
android:id="@+id/informationImageView"
app:srcCompat="@drawable/information"
tools:src="@drawable/information"
/>
Run Code Online (Sandbox Code Playgroud)
的build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.company"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
generatedDensities = []
}
aaptOptions {
additionalParameters "--no-version-vectors"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.txt'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:cardview-v7:23.2.1'
compile 'com.android.support:recyclerview-v7:23.2.1'
compile 'com.android.support:support-v4:23.2.1'
}
Run Code Online (Sandbox Code Playgroud)
图像在android studio的设计窗格中正确显示.但是当我运行应用程序时,图像不会显示.图像位于cardView中,位于recyclerviewfragment中.其他项目正确呈现只有矢量绘图不呈现.
此外,Lint错误显示在布局文件中
unexpected namespace prefix "app" found for tag ImageView app:srcCompat
Run Code Online (Sandbox Code Playgroud)
将此行vectorDrawables.useSupportLibrary = true作为defaultConfig语句的一部分插入build.graddle文件中.我已经使用了这里提供的描述并且它有效.认为您必须注意Gradle 2.0+和Gradle 1.5的配置看起来不同.
无论您使用的Gradle版本如何,您都必须确保您的活动必须扩展AppCompatActivity以提供向量支持.
| 归档时间: |
|
| 查看次数: |
2392 次 |
| 最近记录: |