【问题标题】:Android Vector Drawables becoming blurry when resize to lagre scaleAndroid Vector Drawables在调整到大规模时变得模糊
【发布时间】:2018-11-07 09:29:52
【问题描述】:

我正在尝试使用这张世界地图svg,但是当我调整矢量大小以查看新加坡时,它没有缩放。地图变得模糊。更具体地说,我将 imageView 的宽度和高度设置为 36000dp。
这是矢量drawbles的宽度和高度:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="2000dp"
    android:height="1001dp"
    android:viewportWidth="2000"
    android:viewportHeight="1001">


在我的布局文件中,我已经使用了 app:srcCompat 而不是 src: 。

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:background="#3A6F5C">

    <ImageView
        android:id="@+id/Map_svg"
        android:layout_width="36000dp"
        android:layout_height="36000dp"
        app:srcCompat="@drawable/ic_world_map"
        />

</android.support.constraint.ConstraintLayout>  


这是我的 gradle 文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        vectorDrawables.useSupportLibrary = true
        applicationId "com.example.alan_lin.flora_shipanimation"
        minSdkVersion 22
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

当我升级它时,如何防止它变得模糊?谢谢

【问题讨论】:

    标签: android android-layout user-interface android-vectordrawable


    【解决方案1】:

    我尝试了您共享的 SVG,但它太复杂而无法由 Android 处理,当应用程序尝试在运行时加载时崩溃,并在堆栈跟踪中显示 STRING_TOO_LARGE

    对于您的解决方案,我建议对这些非常复杂的 SVG 使用 PNG。

    还有两个注意事项:

    1. 如果您使用的是正常大小的向量,请不要忘记将 android:scaleType 属性设置为您的 ImageView
    2. 别忘了在你的 Application 扩展中添加这行代码:

       public class App extends Application {
      
       static {
           AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
       }
       ...
      

    【讨论】:

    • 谢谢!也许我需要使用其他 SVG。我尝试了您上面提到的注释,但是它没有帮助使矢量可绘制变得不模糊。
    猜你喜欢
    • 2018-10-17
    • 2013-03-03
    • 2018-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多