Android 如何在更改.setScaleY()和.setScaleX()后定位TextView内容?
我正在尝试制作一个android ESC/POS打印机编辑器UI。ESC/POS在打印文本时几乎没有选项,它们可以混合在一起:小、带下划线、粗体、双宽(宽)、双高(高)。 虽然ESC/POS打印机部件没有问题,但我在尝试用android UI中的文本视图表示它时遇到了一些问题 虽然改变字体大小可以解决“小”的问题,但我正在努力实现 通过设置View.setScaleX(1.5f)和View.setScaleY(1.5f)来设置宽和高 我正在通过编程创建这些视图,并将它们添加到linearLayout容器中 更改比例后,视图边界不会更新。宽选项超出了视图范围。我曾尝试对视图及其父视图使用view.invalidate(),认为它会重新计算边界,但没有成功Android 如何在更改.setScaleY()和.setScaleX()后定位TextView内容?,android,android-layout,textview,escpos,Android,Android Layout,Textview,Escpos,我正在尝试制作一个android ESC/POS打印机编辑器UI。ESC/POS在打印文本时几乎没有选项,它们可以混合在一起:小、带下划线、粗体、双宽(宽)、双高(高)。 虽然ESC/POS打印机部件没有问题,但我在尝试用android UI中的文本视图表示它时遇到了一些问题 虽然改变字体大小可以解决“小”的问题,但我正在努力实现 通过设置View.setScaleX(1.5f)和View.setScaleY(1.5f)来设置宽和高 我正在通过编程创建这些视图,并将它们添加到linearLayo
onClick(View v) {
PrinterCommands.FormatedText textComand = new PrinterCommands.FormatedText("Hello world");
textComand.setTall(r.nextBoolean());
textComand.setUnderlined(r.nextBoolean());
textComand.setBold(r.nextBoolean());
textComand.setWide(r.nextBoolean());
textComand.setSmall(r.nextBoolean());
TextView textView = new TextView(CommandsViewActivity.this);
StringBuilder sb = new StringBuilder("Hello world");
// v.setText(String.valueOf(position));
if (textComand.isSmall()) {
sb.append(" small");
textView.setScaleX(0.5f);
textView.setScaleY(0.5f);
}
if (textComand.isBold()) {
sb.append(" bold");
textView.setTypeface(null, Typeface.BOLD);
}
if (textComand.isTall()) {
sb.append(" tall");
textView.setScaleY(1.5f);
}
if (textComand.isWide()){
sb.append(" wide");
textView.setScaleX(1.5f);
}
if (textComand.isUnderlined()) {
sb.append(" underlined");
SpannableString s = new SpannableString(sb.toString());
s.setSpan(new UnderlineSpan(), 0, s.length(), 0);
textView.setText(s);
} else textView.setText(sb.toString());
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
textView.setGravity(Gravity.START|Gravity.CENTER);
p.setMargins(16,16,16,16);
textView.setLayoutParams(p);
container.addView(textView);
}
});