[英]Background drawable vector not filling screen
I have a problem with a vector drawable which I set as background of my RelativeLayout. 我将我设置为RelativeLayout的背景的vector drawable遇到问题。 It is not filling the screen horizontally. 它不是水平填充屏幕。
Here is the code for my 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>
And the vector Drawable my_drawable, if it helps to have it posted: 向量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>
And the screenshot below. 还有下面的截图。 AS you see it doesn't fill the whole width. 如您所见,它不能填满整个宽度。
Any suggestions/solutions highly appreciated! 任何建议/解决方案高度赞赏!
place image view inside a frame layout 将图像视图放置在框架布局内
<?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>
Looks like a source image your generated the vector drawable from contains some padding. 看起来像是您生成的可绘制矢量从其中生成的源图像包含一些填充。 Make sure to remove it and regenerate drawable again. 确保将其删除并再次重新生成可绘制对象。
I know this is not the solution I was looking for, but rather than playing with vectors, I simply created a shapes drawable XML. 我知道这不是我想要的解决方案,但是我没有创建向量,而是创建了可绘制图形的XML。 My goal was to achieve shadows, hence I started with importing SVGs, but actually I was able to achieve shadows with layer-list of shapes. 我的目标是获得阴影,因此我从导入SVG开始,但是实际上我能够通过形状的图层列表实现阴影。
If anyone ever stumbles upon a solution, I'd be curious to know. 如果有人偶然发现解决方案,我很想知道。
Thanks all! 谢谢大家!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.