kandi background
Explore Kits

android-autofittextview | automatically resizes text to fit perfectly within | Frontend Framework library

 by   grantland Java Version: 0.2.1 License: Apache-2.0

 by   grantland Java Version: 0.2.1 License: Apache-2.0

Download this library from

kandi X-RAY | android-autofittextview Summary

android-autofittextview is a Java library typically used in User Interface, Frontend Framework applications.,roid-autofittextview has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has medium support. You can download it from GitHub, Maven.
A TextView that automatically resizes text to fit perfectly within its bounds.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • android-autofittextview has a medium active ecosystem.
  • It has 4123 star(s) with 686 fork(s). There are 108 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 46 open issues and 35 have been closed. On average issues are closed in 62 days. There are 11 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of android-autofittextview is 0.2.1
This Library - Support
Best in #Frontend Framework
Average in #Frontend Framework
This Library - Support
Best in #Frontend Framework
Average in #Frontend Framework

quality kandi Quality

  • android-autofittextview has 0 bugs and 0 code smells.
This Library - Quality
Best in #Frontend Framework
Average in #Frontend Framework
This Library - Quality
Best in #Frontend Framework
Average in #Frontend Framework

securitySecurity

  • android-autofittextview has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • android-autofittextview code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
This Library - Security
Best in #Frontend Framework
Average in #Frontend Framework
This Library - Security
Best in #Frontend Framework
Average in #Frontend Framework

license License

  • android-autofittextview is licensed under the Apache-2.0 License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
This Library - License
Best in #Frontend Framework
Average in #Frontend Framework
This Library - License
Best in #Frontend Framework
Average in #Frontend Framework

buildReuse

  • android-autofittextview releases are available to install and integrate.
  • Deployable package is available in Maven.
  • Build file is available. You can build the component from source.
  • Installation instructions are not available. Examples and code snippets are available.
This Library - Reuse
Best in #Frontend Framework
Average in #Frontend Framework
This Library - Reuse
Best in #Frontend Framework
Average in #Frontend Framework
Top functions reviewed by kandi - BETA

kandi has reviewed android-autofittextview and discovered the below as its top functions. This is intended to give you an instant insight into android-autofittextview implemented functionality, and help decide if they suit your requirements.

  • Calculate the text size for a given text
  • Performs auto - sizing on the TextView .
  • Initializes the view .
  • Enable or disable the widget .
  • Add a TextView .
  • Set the max lines .
  • Set the maximum line number .
  • Handle text size change
  • Get the autofit helper for the given textView

android-autofittextview Key Features

A TextView that automatically resizes text to fit perfectly within its bounds.

Usage

copy iconCopydownload iconDownload
dependencies {
    compile 'me.grantland:autofittextview:0.2.+'
}

License

copy iconCopydownload iconDownload
Copyright 2014 Grantland Chew

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Android - set text size programatically cuts off words

copy iconCopydownload iconDownload
 //Loop through every textview and get lowest size
    float lowestTextSize = textViews.get(0).getTextSize();
    for (TextView textView : textViews){
        if(lowestTextSize > textView.getTextSize()){
            lowestTextSize = textView.getTextSize();
        }
    }

    lowestTextSize = lowestTextSize / getResources().getDisplayMetrics().scaledDensity;

    //Loop through every textview and set them all to the lowest text size previously found
    for (TextView textView : textViews){
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, lowestTextSize);
        AutofitHelper autofitHelper = AutofitHelper.create(textView);
        autofitHelper.setTextSize(textView.getTextSize());
    }

Community Discussions

Trending Discussions on android-autofittextview
  • Android - set text size programatically cuts off words
Trending Discussions on android-autofittextview

QUESTION

Android - set text size programatically cuts off words

Asked 2017-Sep-01 at 10:00

So I am using a library for resizing the text to fit within bounds: https://github.com/grantland/android-autofittextview. What I am trying to do is to loop through an ArrayList of text view and find the lowest text size and then set that text size to every text view. My Java Code:

//Loop through every textview and get lowest size
        float lowestTextSize = textViews.get(0).getTextSize();
        for (TextView textView : textViews){
            if(lowestTextSize > textView.getTextSize()){
                lowestTextSize = textView.getTextSize();
            }
        }

        lowestTextSize = lowestTextSize / getResources().getDisplayMetrics().scaledDensity;

        //Loop through every textview and set them all to the lowest text size previously found
        for (TextView textView : textViews){
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, lowestTextSize);
        }

My problem is that after setting that size to every textview the size of the textview changes but not the size of the words itself, so I get words cut in half (exception making the word whos size I am using, the one resized by the AutoFit library): enter image description here

Any idea on how to solve this?

My XML code:

<LinearLayout
    android:id="@+id/highestSellingProductLayout"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_weight="1"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3"
        android:gravity="center"
        android:orientation="horizontal">

        <me.grantland.widget.AutofitTextView
            android:id="@+id/highestSellingProduct"
            autofit:minTextSize="15sp"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:maxLines="1"
            android:paddingBottom="5dp"
            android:text="NA"
            android:textAlignment="center"
            android:textColor="@color/colorSuccess"
            android:textSize="22sp"
            android:textStyle="bold" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <me.grantland.widget.AutofitTextView
            autofit:minTextSize="15sp"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="bottom"
            android:maxLines="1"
            android:paddingBottom="5dp"
            android:text="Highest Selling"
            android:textAlignment="center"
            android:textSize="15sp" />
    </LinearLayout>

</LinearLayout>

ANSWER

Answered 2017-Sep-01 at 10:00

I have found the issue. To change the size of text in java using AutofitTextView I had to use autofitHelper on every textview. The following code worked for me:

 //Loop through every textview and get lowest size
    float lowestTextSize = textViews.get(0).getTextSize();
    for (TextView textView : textViews){
        if(lowestTextSize > textView.getTextSize()){
            lowestTextSize = textView.getTextSize();
        }
    }

    lowestTextSize = lowestTextSize / getResources().getDisplayMetrics().scaledDensity;

    //Loop through every textview and set them all to the lowest text size previously found
    for (TextView textView : textViews){
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, lowestTextSize);
        AutofitHelper autofitHelper = AutofitHelper.create(textView);
        autofitHelper.setTextSize(textView.getTextSize());
    }

Source https://stackoverflow.com/questions/45956761

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install android-autofittextview

You can download it from GitHub, Maven.
You can use android-autofittextview like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the android-autofittextview component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

Support

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Explore Related Topics

Share this Page

share link
Consider Popular Frontend Framework Libraries
Compare Frontend Framework Libraries with Highest Support
Compare Frontend Framework Libraries with Highest Security
Compare Frontend Framework Libraries with Permissive License
Compare Frontend Framework Libraries with Highest Reuse
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.