在皮肤 json 文件中指定 TextButton 填充?
Specify TextButton padding in skin json file?
我有一个典型的皮肤 json 文件,就像这里的示例:
https://github.com/libgdx/libgdx/blob/master/tests/gdx-tests-android/assets/data/uiskin.json
是否可以在外观文件中为文本按钮指定 "inner" 填充(文本周围到按钮边缘的 space)- 或者我们只能在运行时以编程方式执行此操作?
谢谢
除了 .json 文件,您还应该有一个 .atlas 文件
在你的 .atlas 文件中,你定义你的按钮
在您的 .atlas 文件中:
Button.png
size: 70,10
format: RGBA8888
filter: Linear,Linear
repeat: none
Button1
rotate: false
xy: 0, 0
size: 30, 30
orig: 30, 30
offset: 0, 0
index: -1
所以如果你的按钮尺寸是 30, 30
那么如果你想让你的按钮在 x 轴上稍微大一点,那么让你的 orig 20, 30
希望你喜欢这个答案
如果您需要更多帮助,请访问
here 或者自己找更多例子
如果你想从 table.
中的代码进行填充
这是来自 wiki table:
的示例
填充
填充是额外的 space 围绕单元格的边缘。
table.add(nameLabel);
table.add(nameText).width(100).padBottom(10); // Sets bottom padding.
table.row();
table.add(addressLabel);
table.add(addressText).width(100).pad(10); // Sets top, left, bottom, right padding.
看这个:
scene2d 中的按钮使用背景可绘制对象来确定填充。据我所知,设置按钮填充的唯一三种可靠方法是
为背景可绘制对象使用 9 补丁可绘制对象。 9补丁定义了自己的padding。
通过使用其 setTopHeight()
、setLeftWidth()
等方法以编程方式修改任何 Drawable 以具有填充。然后以编程方式将此 Drawable 应用为按钮的背景。
编辑: 从 LibGDX 1.7.2 开始,现在可以通过在 JSON 中指定一个 TextureRegionDrawable 来做到这一点文件。使用 TextureRegionDrawable 作为按钮的背景并像这样定义它的填充:
com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable: {
paddedWhite: { region: white, leftWidth: 5, rightWidth: 5, topHeight: 4, bottomHeight: 4 }
}
请注意,如果您只是使用 button.pad(...)
,您的填充设置将在第一次按下按钮时取消。
我有一个典型的皮肤 json 文件,就像这里的示例:
https://github.com/libgdx/libgdx/blob/master/tests/gdx-tests-android/assets/data/uiskin.json
是否可以在外观文件中为文本按钮指定 "inner" 填充(文本周围到按钮边缘的 space)- 或者我们只能在运行时以编程方式执行此操作?
谢谢
除了 .json 文件,您还应该有一个 .atlas 文件 在你的 .atlas 文件中,你定义你的按钮
在您的 .atlas 文件中:
Button.png
size: 70,10
format: RGBA8888
filter: Linear,Linear
repeat: none
Button1
rotate: false
xy: 0, 0
size: 30, 30
orig: 30, 30
offset: 0, 0
index: -1
所以如果你的按钮尺寸是 30, 30
那么如果你想让你的按钮在 x 轴上稍微大一点,那么让你的 orig 20, 30
希望你喜欢这个答案
如果您需要更多帮助,请访问 here 或者自己找更多例子
如果你想从 table.
中的代码进行填充这是来自 wiki table:
的示例填充
填充是额外的 space 围绕单元格的边缘。
table.add(nameLabel);
table.add(nameText).width(100).padBottom(10); // Sets bottom padding.
table.row();
table.add(addressLabel);
table.add(addressText).width(100).pad(10); // Sets top, left, bottom, right padding.
看这个:
scene2d 中的按钮使用背景可绘制对象来确定填充。据我所知,设置按钮填充的唯一三种可靠方法是
为背景可绘制对象使用 9 补丁可绘制对象。 9补丁定义了自己的padding。
通过使用其
setTopHeight()
、setLeftWidth()
等方法以编程方式修改任何 Drawable 以具有填充。然后以编程方式将此 Drawable 应用为按钮的背景。编辑: 从 LibGDX 1.7.2 开始,现在可以通过在 JSON 中指定一个 TextureRegionDrawable 来做到这一点文件。使用 TextureRegionDrawable 作为按钮的背景并像这样定义它的填充:
com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable: { paddedWhite: { region: white, leftWidth: 5, rightWidth: 5, topHeight: 4, bottomHeight: 4 } }
请注意,如果您只是使用 button.pad(...)
,您的填充设置将在第一次按下按钮时取消。