【发布时间】:2017-01-14 02:37:54
【问题描述】:
我用我拥有的路径数据创建了一个 VectorDrawable 文件。但问题是图像没有在总区域的中心对齐,而是创建为左上对齐。看看:
文件:
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="@android:color/white"
android:pathData="M7.144375,6.49965789 L13.196575,0.583973684 C13.333075,0.450552632 13.333075,0.233657895 13.196575,0.0995526316 C13.060075,-0.0331842105 12.838175,-0.0331842105 12.701675,0.0995526316 L6.649475,6.01592105 L0.596575,0.0995526316 C0.460775,-0.0331842105 0.238875,-0.0331842105 0.102375,0.0995526316 C-0.034125,0.233657895 -0.034125,0.450552632 0.102375,0.583973684 L6.154575,6.49965789 L0.102375,12.4153421 C-0.034125,12.5487632 -0.034125,12.7656579 0.102375,12.8997632 C0.170975,12.9661316 0.260575,12.9989737 0.350175,12.9989737 C0.439775,12.9989737 0.529375,12.9654474 0.597975,12.8997632 L6.650175,6.98339474 L12.702375,12.8997632 C12.770975,12.9661316 12.860575,12.9989737 12.950175,12.9989737 C13.039775,12.9989737 13.129375,12.9654474 13.197975,12.8997632 C13.334475,12.7656579 13.334475,12.5487632 13.197975,12.4153421 L7.145775,6.49965789 L7.144375,6.49965789 Z" />
</vector>
现在检查它作为 app:srcCompat 用于 imageView 时的实际外观。
由于我对 VectorDrawables 没有太多经验,有什么办法可以解决这个问题?
我们将不胜感激。
编辑:这就是我使用矢量可绘制对象的方式。
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/close_button"/>
【问题讨论】:
-
发布您的图像查看代码
-
I've created one SVG file否。这称为VectorDrawable,这是else。灵感来自但不等同于 SVG 文件。 -
好的@Rotwang 所以最终我创建了VectorDrawable。如何使其居中对齐?
-
@DrilonBlakqori 请查看更新后的问题
-
嗯.... 在你的 ImageView 中设置
android:gravity和/或android:layout_gravity怎么样?
标签: android svg android-vectordrawable