TextView(およびEditText)がテキストを分割する方法は、内部でBoringLayoutへのプライベート関数呼び出しを介して行われます。したがって、最善の方法は、EditTextをサブクラス化し、これらの関数を書き直すことです。しかし、それは簡単な作業ではありません。
したがって、TextViewクラスには、テキストスタイル用のさまざまなクラスが作成されています。私たちが見ているのはDynamicLayoutです。このクラスでは、StaticLayoutクラス(reflowedと呼ばれる変数内)の参照に到達します。このクラスのコンストラクターには、テキストラップアルゴリズムがあります。
/*
* From the Unicode Line Breaking Algorithm:
* (at least approximately)
*
* .,:; are class IS: breakpoints
* except when adjacent to digits
* / is class SY: a breakpoint
* except when followed by a digit.
* - is class HY: a breakpoint
* except when followed by a digit.
*
* Ideographs are class ID: breakpoints when adjacent,
* except for NS (non-starters), which can be broken
* after but not before.
*/
if (c == ' ' || c == '\t' ||
((c == '.' || c == ',' || c == ':' || c == ';') &&
(j - 1 < here || !Character.isDigit(chs[j - 1 - start])) &&
(j + 1 >= next || !Character.isDigit(chs[j + 1 - start]))) ||
((c == '/' || c == '-') &&
(j + 1 >= next || !Character.isDigit(chs[j + 1 - start]))) ||
(c >= FIRST_CJK && isIdeographic(c, true) &&
j + 1 < next && isIdeographic(chs[j + 1 - start], false))) {
okwidth = w;
ok = j + 1;
ここですべてのラッピングが行われます。したがって、StaticLayout、DynamicLayout、TextView、そして最後にEditTextをサブクラス化する必要があります。これは、悪夢になると確信しています:(すべてのフローがどのように進行するかさえわかりません。必要に応じて、最初にTextViewを確認してください。 getLinesCount呼び出しを確認します-これが開始点になります。