gpt4 book ai didi

android - 特定字体的文本从前面被截断

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:15:53 26 4
gpt4 key购买 nike

us denealian cursive font 新行中每个单词的第一个字母被截断。 enter image description here

请看这张带有填充的图片。如果我不使用任何填充,它将像图 2 中的一样 enter image description here

这是我的代码

<com.font.anything.writinghelper
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textColor="#000000"
android:padding="20dip"
android:textSize="60sp"
android:text="japanese google donkey elephant ostrich"
/>

这里的 writing helper 是一个扩展 textview 的类,只是为了给文本加下划线

     protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
Rect r = mRect;
int padding =55;
Paint paint = mPaint;
int count = getLineCount();
for (int i = 0; i < count; i++) {
int baseline = getLineBounds(i, r);
canvas.drawLine(r.left - padding, baseline, r.right + padding,
baseline, paint);
}
super.onDraw(canvas);
}

有人能帮忙吗?

编辑

要求截图

enter image description here

有没有办法在 TextView 的左侧放置一些额外的空间?

最佳答案

最后我解决了这个问题。这是一个字体问题,我不确定它是否可以通过任何其他方式解决。所以我所做的是,首先获取 TextView 布局并获取结束和开始每行并因此在每行中获取字符串。现在在每行前面附加空格。这是完整的代码。可能会帮助其他人。

    ArrayList<String> lines = new ArrayList<String>();
ArrayList<String> newLines = new ArrayList<String>();
String line="";
String text = getText().toString();
Layout layout = getLayout();
int start=0;
int end;

for (int i=0; i<count; i++) {
end = layout.getLineEnd(i);

lines.add(text.substring(start,end));
line = lines.get(i);
start = end;
String nwText = "";
nwText = " "+ line+" ";
newLines.add(nwText);
}
Paint mPaint = getPaint();
int i = 0;
// String[] textLines = Results.split("\\n+");
//float textsize = getTextSize();

for (String textLine : newLines)
{
// mPaint.setTextSize(textsize);
int baseline = getLineBounds(i, r);
canvas.drawText(textLine, 0, baseline, mPaint);
i++;
}

关于android - 特定字体的文本从前面被截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28576797/

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