Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AutoSizingTextView

Yuji Koketsu
November 28, 2017

 AutoSizingTextView

Yuji Koketsu

November 28, 2017
Tweet

More Decks by Yuji Koketsu

Other Decks in Programming

Transcript

  1. WHAT IS AUTOSIZING TEXTVIEW? AUTOSIZING TEXTVIEW IS… ▸ Android O

    (API 26) ~ ▸ ϨΠΞ΢τʹ͋ͬͨϑΥϯταΠζΛ ࣗಈͰબఆͯ͘͠ΕΔ ▸ supportϥΠϒϥϦ΋͋ΔΑ
  2. AUTOSIZING TEXTVIEW if (mEllipsize != TextUtils.TruncateAt.MARQUEE) { // In a

    fixed-height view, so use our new text layout. if (mLayoutParams.height != LayoutParams.WRAP_CONTENT && mLayoutParams.height != LayoutParams.MATCH_PARENT) { autoSizeText(); invalidate(); return; } // Dynamic height, but height has stayed the same, // so use our new text layout. if (mLayout.getHeight() == oldht && (mHintLayout == null || mHintLayout.getHeight() == oldht)) { autoSizeText(); invalidate(); return; } } TextView.java > checkForRelayout()
  3. AUTOSIZING TEXTVIEW @Override protected void onLayout(boolean changed, int left, int

    top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); if (mDeferScroll >= 0) { int curs = mDeferScroll; mDeferScroll = -1; bringPointIntoView(Math.min(curs, mText.length())); } // Call auto-size after the width and height have been calculated. autoSizeText(); } TextView.java > onLayout(c, l, t, r, b)
  4. AUTOSIZING TEXTVIEW TextView.java > applySingleLine(s, a, c) private void applySingleLine(boolean

    singleLine, boolean applyTransformation, boolean changeMaxLines) { mSingleLine = singleLine; if (singleLine) { setLines(1); setHorizontallyScrolling(true); ɹɹɹɹ ...