【问题标题】:Using vector images with android:drawableTop before API level 21在 API 级别 21 之前使用带有 android:drawableTop 的矢量图像
【发布时间】:2017-03-12 12:40:48
【问题描述】:

我正在开发一个需要在 Android 设备上一直运行到 Android Gingerbread (2.3) 的应用程序,并且似乎在显示 SVG 图像时遇到了一些问题。

我了解,支持库允许我通过将这一行放在我的应用级别 build.gradle 中来使用矢量图像:

vectorDrawables.useSupportLibrary = true

然后我可以使用各种支持库类或android:srcCompatImageView 中显示 SVG

这里的问题是我没有使用 ImageView 来显示我的 SVG。我正在使用带有android:drawableTop 属性的TextView 来显示我的SVG,如下所示:

<TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/text_no_notes"
        android:textAlignment="center"
        android:drawableTop="@drawable/ic_notepad"
        android:id="@+id/textView"
        android:textAppearance="@style/TextAppearance.AppCompat.Medium.Inverse" />

由于android:drawableTop 不使用支持库矢量图像,因此应用程序在运行时会在“L”之前的设备上崩溃。有什么解决方法可以让android:drawableTop 工作,还是我只是拆分TextView 并使用android:srcCompat

【问题讨论】:

    标签: android svg android-support-library vector-graphics


    【解决方案1】:

    无法将它与系统 TextView 一起使用。 (相关源码:5.1.1/4.4.4

    您可以使用自定义 View 类,但在这一点上,我认为您最好使用带有 ImageView 和 TextView 的 LinearLayout。

    【讨论】:

    • 呃,我认为这最终会成为答案。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-16
    • 2015-01-15
    • 2021-12-10
    相关资源
    最近更新 更多