【问题标题】:Background drawable vector not filling screen背景可绘制矢量不填充屏幕
【发布时间】:2017-09-25 18:55:27
【问题描述】:

我有一个矢量 drawable 问题,我将它设置为我的 RelativeLayout 的背景。它没有水平填充屏幕。

这是我的 RelativeLayout 的代码:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/my_drawable">

        ...
        some text views etc.
        ...

    </RelativeLayout>

还有矢量 Drawable my_drawable,如果发布它有帮助的话:

<vector android:height="24dp" android:viewportHeight="110.0"
    android:viewportWidth="110.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:name="border_path" android:fillColor="@color/color_1" android:fillAlpha="1"
        android:pathData="M105.13,107.51L4.89,107.51A2.38,2.38 99.69,0 1,2.51 105.13L2.51,4.89A2.38,2.38 119.37,0 1,4.89 2.51L105.13,2.51A2.38,2.38 119.37,0 1,107.51 4.89L107.51,105.13A2.38,2.38 99.69,0 1,105.13 107.51z"
        android:strokeAlpha="1" android:strokeColor="@color/color_2" android:strokeWidth="5"/>
</vector>

还有下面的截图。如您所见,它并没有填满整个宽度。

非常感谢任何建议/解决方案!

【问题讨论】:

  • 图片未加载

标签: android android-drawable android-relativelayout android-vectordrawable


【解决方案1】:

将图像视图放置在框架布局中

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout 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">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="fitXY"
                android:src="@drawable/sample"
                android:text="Hello World!" />

        </FrameLayout>

    </RelativeLayout>

【讨论】:

  • 同样的问题,这里没有变化。
【解决方案2】:

看起来您生成的可绘制矢量的源图像包含一些填充。确保将其删除并重新生成可绘制对象。

【讨论】:

  • 我试过了,好像没有padding。我查看了 pathData 中的位置,似乎到达了视口属性指定的角落(这里的逻辑很简单,我不是矢量图形专家,可能是错误的)。
【解决方案3】:

我知道这不是我正在寻找的解决方案,但我没有玩矢量,而是简单地创建了一个可绘制形状的 XML。我的目标是实现阴影,因此我从导入 SVG 开始,但实际上我能够通过形状的图层列表实现阴影。

如果有人偶然发现解决方案,我很想知道。

谢谢大家!

【讨论】:

    猜你喜欢
    • 2013-11-18
    • 1970-01-01
    • 2012-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-14
    • 1970-01-01
    • 2015-06-25
    相关资源
    最近更新 更多