This is based on an open source autosizing textview for Android.

Overview

SizeAdjustingTextView

This is based on an open source autosizing textview for Android I found a few weeks ago. The initial approach didn't resize multiple lines and wasn't maintained to keep up with changes in Android. I decided to go ahead and create this as a place to preserve the auto sizing text view as well as giving it a platform for some change and to possibly add some features and functionality.

Usage

To use the SizeAdjustingTextView make sure you have the custom view somewhere in your project. From there when using XML Layouts you can simply use the com.some.package.name.SizeAdjustingTextView widget and thats it. From there you need to make sure that you set a text size as the baseline for the view.

<com.example.sizeadjustingtextview.view.SizeAdjustingTextView
        android:layout_width="fill_parent"
        android:layout_height="100dp"
        android:id="@+id/topBox"
        android:layout_below="@id/text_input"
        android:gravity="center"
        android:padding="0dp"
        android:textSize="60sp" />

Lastly when using custom views in XML, make sure you have the XLMNS tag in the root of the layout tag.

 xmlns:app="http://schemas.android.com/apk/res/com.example.SizeAdjustingTextView"

I didn't want to make this a library because there is no need for adding a library for one view. Just port over the SizeAdjustingTextView and you should be good.

You might also like...
XliteKt is an open-source, and forever open-source Kotlin based OSRS Emulator for educational purposes.

xlitekt Introduction XliteKt is an open-source, and forever open-source Kotlin based OSRS Emulator for educational purposes. Currently built around th

A simple and flexible Checked TextView or Checkable TextView
A simple and flexible Checked TextView or Checkable TextView

CheckableTextView Checkable TextView [KOTLIN] ⚡ A simple and flexible Checked TextView or Checkable TextView written in Kotlin ⚡ What's New Animation

Mentions-TextView - Make Mentions and hashtags clickable in Textview
Mentions-TextView - Make Mentions and hashtags clickable in Textview

Mentions Textview Custome Textview with Mentions and hashtags being clickable. D

BaseAnimation network Android animation set, custom controls, nearly 200 kinds of source code! BaseAnimation, if a new version is updated automatically to remind everyone, I hope everyone will contribute their animated XML files or other source, together to create this open source app! Source++ is an open-source live coding platform. Add breakpoints, logs, metrics, and tracing to live production applications
Source++ is an open-source live coding platform. Add breakpoints, logs, metrics, and tracing to live production applications

Source++ is an open-source live coding platform. Add breakpoints, logs, metrics, and distributed tracing to live production software in real-time on-d

A TextView that automatically fit its font and line count based on its available size and content
A TextView that automatically fit its font and line count based on its available size and content

AutoFitTextView A TextView that automatically fit its font and line count based on its available size and content This code is heavily based on this S

Open-source telematics app for Android. The application is suitable for UBI (Usage-based insurance), shared mobility, transportation, safe driving, tracking, family trackers, drive-coach, and other driving mobile applications
Open-source telematics app for Android. The application is suitable for UBI (Usage-based insurance), shared mobility, transportation, safe driving, tracking, family trackers, drive-coach, and other driving mobile applications

TelematicsApp-Android with Firebase© integration Description This Telematics App is created by DATA MOTION PTE. LTD. and is distributed free of charge

Lemuroid is an open-source emulation project for Android based on Libretro
Lemuroid is an open-source emulation project for Android based on Libretro

Lemuroid Description Lemuroid is an open-source emulation project for Android based on Libretro. Its main goal is ease of use, good Android integratio

NekoX is an free and open source third-party Telegram client, based on Telegram-FOSS with features added.

NekoX NekoX is an free and open source third-party Telegram client, based on Telegram-FOSS with features added. We are no longer able to update versio

PngNote is a free, open-source, handwriting note-taking app based on BOOX SDK.
PngNote is a free, open-source, handwriting note-taking app based on BOOX SDK.

PngNote is a free, open-source, handwriting note-taking app based on BOOX SDK. Use BOOX SDK: Leverage raw-rendering feature, similar stylus lag to the

🚧 A fully open-source project for creating and maintaining a Kotlin-based Minecraft: Java Edition server.

Hexalite: Java Edition ⚠️ WARNING: The Hexalite Network is a work in progress. It is not yet ready for production. You may encounter bugs and other is

🚧 A fully open-source project for creating and maintaining a Kotlin-based Minecraft: Java Edition server.

Hexalite: Java Edition ⚠️ WARNING: The Hexalite Network is a work in progress. It is not yet ready for production. You may encounter bugs and other is

YAML-based source-based kotlin module descriptors

kproject - Liberate your Kotlin projects YAML-based source-based kotlin module descriptors that runs on top of gradle. Define your kotlin multiplatfor

() An Android TextView with a shimmering effect
() An Android TextView with a shimmering effect

Shimmer for Android This library is DEPRECATED, as I don't have time to mainatin it anymore. But feel free to go through the code and copy that into y

() Android experiment showing a sinking TextView
() Android experiment showing a sinking TextView

Titanic for Android This library is DEPRECATED, as I don't have time to mainatin it anymore. But feel free to go through the code and copy that into y

Android's TextView that can expand/collapse like the Google Play's app description

ExpandableTextView ExpandableTextView is an Android library that allows developers to easily create an TextView which can expand/collapse just like th

Android TextView with rich support of compound drawables
Android TextView with rich support of compound drawables

TextViewRichDrawable This is a tiny library which empowers TextView's (and its inheritors) compound drawables with size specifying, vector support and

Android's TextView that can expand/collapse like the Google Play's app description

ExpandableTextView ExpandableTextView is an Android library that allows developers to easily create an TextView which can expand/collapse just like th

Comments
  • Doesn't work when increasing the view's height.

    Doesn't work when increasing the view's height.

    Here's how to fix it.

    private float findNewTextSize(int width, int height, CharSequence text) {
            TextPaint textPaint = new TextPaint(getPaint());
            float targetTextSize = getMaxTextSize();  // Start from the max size
            int textHeight = getTextHeight(text, textPaint, width, targetTextSize);
            while(textHeight > height && targetTextSize > mMinTextSize) {
                targetTextSize = Math.max(targetTextSize - 1, mMinTextSize);
                textHeight = getTextHeight(text, textPaint, width, targetTextSize);
            }
            return targetTextSize;
        }
    
    opened by sebouh00 0
  • Bug: very slow , truncates text and puts characters on next line

    Bug: very slow , truncates text and puts characters on next line

    All I wanted is that it would fit into it boundaries.

    Using the next XML will make it very slow and also truncate the text:

    <com.omitneedlesscode.sizeadjustingtextview.SizeAdjustingTextView
        android:layout_width="180dp"
        android:layout_height="203dp"
        android:layout_below="@+id/text_input"
        android:maxLines="2"
        android:text="content text sample"
        android:textSize="1000dp"/>
    

    And this is what I got :

    device-2016-02-09-162003

    plus it was very slow.

    note that I've set 1000dp so that it will resize to the max that it can. a better way is to do it in code.

    I think it should work this way: using the current configurations of the TextView, if it failed to fit, try to find a font that will make it fit. if failed with this, try to add a line (till reaching max lines that were set), and for each iteration there try to fit the font.

    For the font checking, I think it should use binary search, instead of decreasing by 1 .

    opened by AndroidDeveloperLB 0
Owner
Elliott Chenger
Elliott Chenger
() Android experiment showing a sinking TextView

Titanic for Android This library is DEPRECATED, as I don't have time to mainatin it anymore. But feel free to go through the code and copy that into y

Romain Piel 1.8k Dec 15, 2022
Android's TextView that can expand/collapse like the Google Play's app description

ExpandableTextView ExpandableTextView is an Android library that allows developers to easily create an TextView which can expand/collapse just like th

Manabu S. 4k Jan 8, 2023
A TextView that automatically resizes text to fit perfectly within its bounds.

AutoFitTextView A TextView that automatically resizes text to fit perfectly within its bounds. Usage dependencies { compile 'me.grantland:autofitt

Grantland Chew 4.2k Jan 8, 2023
A TextView that simulates the effect from the app Secret where the characters fade in/out at different speeds.

SecretTextView A TextView that simulates the effect from the app Secret where the characters fade in/out at different speeds. How To Use Use it just l

Matt Kula 611 Nov 7, 2022
An easy, flexible way to add a shimmering effect to any view in an Android app.

Shimmer for Android Shimmer is an Android library that provides an easy way to add a shimmer effect to any view in your Android app. It is useful as a

Facebook 5.1k Dec 31, 2022
:page_facing_up: Android Text Full Jusiftication / Wrapping / Justify / Hyphenate - V2.0

LIBRARY IS NO LONGER MAINTAINED If you want to adopt + maintain this library, please drop me a message - [email protected] Android Full Justific

Mathew Kurian 1.9k Dec 29, 2022
RoundedLetterView like the one in Android 5.0 Contacts app

RoundedLetterView RoundedLetterView like the one in Android 5.0 Contacts app Attributes to choose from: rlv_titleText - The text in the first row. rlv

Pavlos-Petros Tournaris 653 Nov 11, 2022
A editable text with a constant text/placeholder for Android.

ParkedTextView A EditText with a constant text in the end. How to use <com.goka.parkedtextview.ParkedTextView xmlns:app="http://schemas.android.co

goka 270 Nov 11, 2022
Android Library to make it easy to create CodeEditor or IDE that support any languages and themes

CodeView Android Library to make it easy to create your CodeEditor or IDE for any programming language even for your programming language, just config

Amr Hesham 294 Jan 6, 2023
This is based on an open source autosizing textview for Android.

SizeAdjustingTextView This is based on an open source autosizing textview for Android I found a few weeks ago. The initial approach didn't resize mult

Elliott Chenger 255 Dec 29, 2022