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...
Android slanted TextView.
Android slanted TextView.

SlantedTextView Android slanted TextView . 中文版 Preview Gradle compile 'com.haozhang.libary:android-slanted-textview:1.2' XML Layout com.haozhang.lib.

() 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

An Android TextView that always displays an auto refreshing relative time span with respect to a reference time
An Android TextView that always displays an auto refreshing relative time span with respect to a reference time

android-ago This library provides RelativeTimeTextView, a custom TextView that takes a reference time and always displays the relative time with respe

a super textview for android
a super textview for android

SuperTextView 重磅推出SuperTextView2.x版本,属性参数相比1.x有些变化,1.x的用户升级2.x的时候请注意 1、功能描述 SuperTextView是一个功能强大的View,可以满足日常大部分布局样式,开发者可已自行组合属性配置出属于自己风格的样式!可能描述起来没有概念

Build valid HTML for Android TextView
Build valid HTML for Android TextView

HTML Builder Build valid HTML for Android TextView. Description There is a lovely method on the android.text.Html class, fromHtml(), that converts HTM

ExpandableTextView - Read More TextView for Android
ExpandableTextView - Read More TextView for Android

ExpandableTextView Read More TextView for Android Usage Gradle dependencies { implementation 'com.wayne.expandabletextview:expandable-textview:1.1

Animation effects to text, not really textview
Animation effects to text, not really textview

HTextView Animation effects with custom font support to TextView see iOS Effects see Flutter Effects Screenshot type gif Scale Evaporate Fall Line Typ

A TextView that automatically resizes text to fit perfectly within its bounds.
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

A Custom TextView with trim text
A Custom TextView with trim text

ReadMoreTextView A Custom TextView with trim text Download To add the ReadMoreTextView library to your Android Studio project, simply add the followin

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
Mentions-TextView - Make Mentions and hashtags clickable in Textview

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

null 2 Jan 9, 2022
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

null 899 Jan 2, 2023
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 Dec 28, 2022
A library to show emoji in TextView, EditText (like WhatsApp) for Android

Discontinued This projected is discontinued. Please consider using other alternative, i.e EmojiCompat. Contact me if you want to continue working on a

Hieu Rocker 3.6k Jan 5, 2023
Android experiment showing a sinking TextView

Titanic is an Android experiment reproducing this effect.

Romain Piel 1.8k Dec 15, 2022
Advanced Android TextView

Advanced Android TextView Companion app for my Advanced Android TextView talk, demostrating: Animated CompoundDrawable Text shadow Custom font Non-bre

Chiu-Ki Chan 1.2k Dec 9, 2022
An extension of Android's TextView, EditText and Button that let's you use the font of your choice

AnyTextView (deprecated) Note: AnyTextView is no longer being maintained. I recommend replacing AnyTextView with the Calligraphy library instead. Frus

Hans Petter Eide 165 Nov 11, 2022
Form validation and feedback library for Android. Provides .setText for more than just TextView and EditText widgets. Provides easy means to validate with dependencies.

android-formidable-validation Form validation and feedback library for Android. Provides .setText for more than just TextView and EditText widgets. Pr

Linden 147 Nov 20, 2022
Simple way to create linked text, such as @username or #hashtag, in Android TextView and EditText

Simple Linkable Text Simple way to create link text, such as @username or #hashtag, in Android TextView and EditText Installation Gradle Add dependenc

Aditya Pradana Sugiarto 76 Nov 29, 2022
Lightweight android library for highlighting sections of a textview, with optional callbacks.

Linker Lightweight android library for highlighting Strings inside of a textview (ignoring case), with optional callbacks. Language: Java MinSDK: 17 J

Josh Gainey 35 Apr 30, 2022