【发布时间】:2016-12-05 05:31:20
【问题描述】:
我正在开发一个类似于填补空白的应用程序。我想从差距中获取信息。此代码将自动测量间隙的位置。
String Str = new String(text);
System.out.print("Found Index :");
System.out.println(Str.indexOf('_'));
Log.e("Index", String.valueOf(Str.indexOf('_')));
Rect bounds = new Rect();
Paint textPaint = questionView.getPaint();
textPaint.getTextBounds(text, 0, Str.indexOf('_'), bounds);
int height = bounds.height();
int firstWidth = bounds.width();
textPaint.getTextBounds(text, Str.indexOf('_') + 3, text.length(), bounds);
int secondWidth = bounds.width();
Log.e("String Bounds", "firstWidth " + firstWidth + " secondWidth " + secondWidth);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(firstWidth, 0, secondWidth, 0);
answerText.setLayoutParams(lp);
这段代码的输出类似这样:
现在问题出现了。如何设置用户可以输入的editText的长度以填补空白?
我想包括整个句子是“这是一个句子”。该句子将像“这是___句子”一样出现在用户面前。如果用户触摸间隙,我想接受输入。我们也可以放置一个像“Enter”这样的按钮来接受输入。如何正确地做到这一点,因为现在我可以测量句子的宽度和高度。
【问题讨论】:
-
想要更多解释
标签: java android xml android-edittext