You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何96x96 SVG图片在Android API 16与API 27中显示模糊?

Android Studio生成SVG并应用于LinearLayout布局实操

我来梳理下你用Android Studio生成SVG并应用到LinearLayout布局的操作,整理如下:

已完成的操作

  • 通过Android Studio生成了96x96尺寸的SVG图片资源
  • 尝试将该SVG应用到以下LinearLayout布局中(注:原布局代码未完整,以下为你提供的现有部分):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:gravity="center">

    <LinearLayout
        android:padding="8dp"
        android:id="@+id/linear_layout"
        android:layout_width="wrap_content"
        android:layout_h...

补充实用提示

如果你的需求是在LinearLayout中展示这张SVG,这里给你一个完整的示例参考:

  • 确保SVG资源已正确放置在res/drawable目录下(注意文件名不要包含大写或特殊字符)
  • 通常我们会在LinearLayout中嵌套ImageView来承载SVG,因为LinearLayout本身是容器控件,直接设置背景也可以,但ImageView更适合展示矢量图:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:gravity="center">

    <LinearLayout
        android:padding="8dp"
        android:id="@+id/linear_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <!-- 引用你的SVG资源 -->
        <ImageView
            android:layout_width="96dp"
            android:layout_height="96dp"
            app:srcCompat="@drawable/your_generated_svg"
            android:contentDescription="Generated SVG icon" />
    </LinearLayout>
</LinearLayout>

另外,使用app:srcCompat而不是android:src可以更好地支持矢量图在低版本Android系统上的兼容性,记得确保你的项目已经启用了矢量图支持(通常Android Studio新建项目默认已开启)。

内容的提问来源于stack exchange,提问作者Cheok Yan Cheng

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 03:56:13