codenameone - 与创建的 TTF 字体垂直对齐
问题描述
在 Android 上(在模拟器或 IOS 中工作正常)在标签上使用创建的 TTF 字体(来自文件)时,不要将图标与字体垂直对齐,字体在顶部。当我使用本机字体时,效果很好。
我用于测试用例的表单代码,如您在 ScreenShots、IOS 和 Simulador 上所见,Valign 位于 Label 和 Picker 的中心,但在 Android 上对齐在 Top,这在所有组件中都取得了成功
package test.kandy;
import com.codename1.ui.Display;
import com.codename1.ui.Font;
import com.codename1.ui.FontImage;
import com.codename1.ui.Form;
import com.codename1.ui.Label;
import com.codename1.ui.layouts.BoxLayout;
import com.codename1.ui.plaf.Style;
import com.codename1.ui.spinner.Picker;
public class ShaiForm extends Form {
private Form previous;
public ShaiForm() {
setLayout(new BoxLayout(BoxLayout.Y_AXIS));
int fontSize = Display.getInstance().convertToPixels(3);
Font appFont = Font.createTrueTypeFont("Suisse Int'l", "Suisse Int'l.ttf" ).derive(fontSize, Font.STYLE_PLAIN);;
FontImage fntImage = FontImage.createFixed("\uE161", FontImage.getMaterialDesignFont(), 0x0, 100, 100);
Label labelCustomTTF = new Label ("custom TTF");
Style labelStyle = labelCustomTTF.getAllStyles();
labelStyle.setFont(appFont);
labelCustomTTF.setIcon(fntImage);
Label labelNative = new Label ("native Font");
labelNative.setIcon(fntImage);
Picker stringPickerCustom = new Picker();
Style pickerStyle = stringPickerCustom.getAllStyles();
pickerStyle.setFont(appFont);
stringPickerCustom.setType(Display.PICKER_TYPE_STRINGS);
stringPickerCustom.setStrings("custom TTF Font");
stringPickerCustom.setText("custom TTF Font");
Picker stringPickerNative = new Picker();
stringPickerNative.setType(Display.PICKER_TYPE_STRINGS);
stringPickerNative.setStrings("native Font");
stringPickerNative.setText("native Font");
add(labelCustomTTF);
add(labelNative);
add(stringPickerCustom);
add(stringPickerNative);
}
public void show() {
previous = Display.getInstance().getCurrent();
super.show();
}
public void goBack(){
previous.showBack();
}
}
解决方案
推荐阅读
- vb.net - 组合框不显示信息 VB.NET
- apache-spark - 比较具有特定误差范围的值
- python - Conda 环境:libcblas.so.3:无法打开共享对象文件:没有这样的文件或目录
- python - 如何对已应用 PCA 的数据集使用 shap_value 解释器
- javascript - 在 FlatList React Native 中过滤数据
- c - 如何通过套接字打开一个html文件
- python - 如何实现均值偏移(Python)?
- php - 带有通知的空 XML 节点:尝试获取非对象的属性“ref”
- r - 在 R 的 for 循环中粘贴0
- python - 如何设置我的路径,以便它与作为包本地安装的 Python 代码一起使用