Android 图层列表可绘制移动调整项目位置
如何将
放置在
Drawable 中?感谢您的任何帮助。
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/radio_uncheck" /> //24dp from vector assset
<item
android:drawable="@drawable/check_mark" /> //24dp from vector asset
</layer-list>
How to positon the <item>
inside <layer-list>
Drawable? Thanks for any help.
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/radio_uncheck" /> //24dp from vector assset
<item
android:drawable="@drawable/check_mark" /> //24dp from vector asset
</layer-list>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用项目标记的
android:left
和android:top
作为复选标记将使复选标记向上和向右移动,但它也会缩小我所选择的复选标记。不要认为你正在寻找。我可以想到另外两种方法来解决这个问题:第一种是编辑复选标记可绘制以移动它。您可以使用 InkScape 等编辑器来完成此操作,还有其他编辑器。您可能需要稍微调整整体大小以适应移动的复选标记。我更喜欢这种方法。
第二种方法是编写一个自定义 LayerDrawable 来覆盖
draw()
方法来偏移复选标记。如果您可能需要对其他可绘制对象执行此操作,我可能更喜欢此方法。如果没有,我建议只执行第一个建议。如果您愿意放弃可绘制图层,您还可以使用translateX和translateY通过几个视图来完成您所需要的。我确信还有其他方法。
Using
android:left
andandroid:top
of the item tag for the check mark will shift the check up and to the right, but it will also shrink the check mark which I don't think you are looking for.I can think of two other ways to approach this: The first is to just edit the check mark drawable to shift it. You can do this with an editor such as InkScape and there are others. You may need to adjust the overall size slightly to accommodate the shifted check mark. I prefer this approach.
The second approach would be to write a custon LayerDrawable that would override the
draw()
method to offset the check mark. I might prefer this method if this is something you may need to do with other drawables. If not, I suggest just doing the first suggestion.If you are willing to abandon the layer drawable, you can also accomplish what you need with a couple of views using translateX and translateY. I am sure that there are other approaches, too.
我最终选择修改SVG图像来满足我的需求,过程如下:
转到“https://materialdesignicons.com/” ->查找图像->下载 SVG 图像。
转到“https://editor.method.ac/” -> “文件”-> “打开 SVG...”->选择 SVG 文件 -> “打开”。
在右侧面板上调整画布宽度和高度。
调整导入的SVG图像的位置。
“文件”-> “保存图像...”->重命名文件-> “下载”。
将 SVG 图像作为矢量资源导入 Android Studio。
I finally choose to modify the SVG image to meet my needs, following is the process:
Go to "https://materialdesignicons.com/" -> find image -> download SVG image.
Go to "https://editor.method.ac/" -> "File" -> "Open SVG..." -> choose SVG file -> "Open".
Adjust canvas width and height on the right panel.
Adjust the positon of the imported SVG image.
"File" -> "Save Image..." -> rename file -> "Download".
Import the SVG image to Android Studio as vector asset.