gpt4 book ai didi

Android 在一侧的 XML 中覆盖 9 补丁填充

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:51:30 25 4
gpt4 key购买 nike

当使用 9 补丁图像作为背景时,填充似乎总是来自 9 补丁图像。即使您不在 9 补丁图像中使用填充条,它也会使用可绘制对象。

If the padding lines are not included, Android uses the left and top lines to define this drawable area.

http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch

但是您可以使用 android:padding=0dp 或 =Xdp 在 XML 中覆盖它。不幸的是,使用 android:paddingLeft=Xdp 不起作用。所以你被统一填充困住了。我试过这样做:

  android:padding="2dp"
android:paddingLeft="20dp"

它对左边的填充没有影响。将它们放在 styles.xml 中会产生类似的结果。

我见过的唯一解决这个问题的技巧是在代码中设置填充。

最佳答案

如果 (android:padding presented) 它覆盖所有其他填充值else if (android:paddingXXX presented) 它覆盖 bg drawable paddingXXX (XXX = Left|Right|Top|Bottom)else if (view has drawable bg) padding values from this drawable (nine-patch in your case) 将被使用否则将应用默认填充(通常为零)

所以不要使用 android:padding="2dp"。填充属性覆盖一切。只需使用 paddingLeft = 20dp、paddingTop = 2dp、paddingRight = 2dp、paddingBottom = 2dp。

或者您可以设置 paddingLeft = 20dp,其他填充值将从 bg drawable 中获取。

关于Android 在一侧的 XML 中覆盖 9 补丁填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14095170/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com