[英]Android How to Remove white space / padding around vector asset in ImageView?
[英]Android How to Remove the Inner Padding of a Vector Asset Drawable
我的矢量可從 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>
我的布局:
<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>
當前output:
如何刪除此矢量可繪制對象的內部填充? 任何幫助將不勝感激。
好的,這是我提出的解決方案,不是完美的答案,但滿足我的需求。
像這樣修改 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>
結果:
這個解決方案的好處是無論你如何改變ImageView
的大小,目標形狀都會保持它的位置(在我的例子中是底部),所以不需要費心使用RelativeLayout
,只需使用LinearLayout
。
“pivot(12, 12)”解釋: https : //stackoverflow.com/a/51659233/3466808
您可以使用 (pivotX, pivotY, scaleX, scaleY) 查看group
標簽並修改資產代碼
請看例子[這里]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.