2016-03-25 28 views
5

繪製/ information.xml不露面應用:srcCompat - 矢量繪製顯示了在設計預覽,但在應用

<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> 

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" 
    /> 

的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' 
} 

該圖像在android studio的設計窗格中正確顯示。但是當我運行應用程序時,圖像不顯示。該圖像位於recyclerviewfragment中的cardView中。其他項目渲染正確只有矢量繪製不渲染。

此外,皮棉錯誤在佈局文件

unexpected namespace prefix "app" found for tag ImageView app:srcCompat 

回答

6

顯示了插入此行vectorDrawables.useSupportLibrary = true到您build.graddle文件作爲defaultConfig語句的一部分。我已經使用了提供的說明here,它的工作原理。認爲你必須知道Gradle 2.0+和Gradle 1.5的配置看起來不同。

無論您使用的是哪種Gradle版本,您都必須確保您的活動必須擴展AppCompatActivity以提供向量支持。

+0

會調查並回復你。我在上一個項目中遇到了這個問題。謝謝! – q126y

+0

浪費了關鍵的2小時,然後偶然發現了這一點。非常感謝。 – Androidster

+0

謝謝爲我工作 – Richi

1

我在遇到問題時找到了答案。 快速的回答是,你應該使用android.support.v7.widget.AppCompatImageView應用:srcCompat

link解釋。

相關問題