[英]Android How to Remove the Inner Padding of a Vector Asset Drawable
My vector drawable from Vector Asset:我的矢量可从 Vector Asset 中绘制:
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="@android:color/holo_purple"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M7,14l5,-5 5,5z" />
</vector>
My layout:我的布局:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/ic_baseline_arrow_drop_up_24" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/background"
android:text="Hi, my name is Sam"
android:textColor="@android:color/white"
android:textSize="30sp" />
</LinearLayout>
Current output:当前output:
How to remove the inner padding of this vector drawable?如何删除此矢量可绘制对象的内部填充? Any help will be appreciated.
任何帮助将不胜感激。
Ok, here is the solution I come up with, not the perfect answer but meets my need.好的,这是我提出的解决方案,不是完美的答案,但满足我的需求。
Modify the Vector Drawable like this:像这样修改 Vector Drawable:
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="@android:color/holo_purple"
android:viewportWidth="24"
android:viewportHeight="24">
<group //key point
android:pivotX="12" //(12, 12) is the center accordig to the viewport, see link below
android:pivotY="12"
android:scaleX="2.0" //twice bigger, adjust as needed
android:scaleY="2.0"
android:translateY="8"> //move downward, asjust as needed
<path
android:fillColor="@android:color/white"
android:pathData="M7,14l5,-5 5,5z" />
</group>
</vector>
Result:结果:
The benefit of this solution is that no matter how you change the size of the ImageView
, the target shape remains its position (at the bottom in my case), so no need to bother with RelativeLayout
, just go with LinearLayout
.这个解决方案的好处是无论你如何改变
ImageView
的大小,目标形状都会保持它的位置(在我的例子中是底部),所以不需要费心使用RelativeLayout
,只需使用LinearLayout
。
"pivot(12, 12)" explain: https://stackoverflow.com/a/51659233/3466808 “pivot(12, 12)”解释: https : //stackoverflow.com/a/51659233/3466808
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.