Convert Figma logo to code with AI

Manabu-GT logoExpandableTextView

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

4,084
791
4,084
45

Top Related Projects

RichEditor for Android is a beautiful Rich Text WYSIWYG Editor for Android.

:page_facing_up: Android Text Full Jusiftication / Wrapping / Justify / Hyphenate - V2.0

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

Android平台下的富文本解析器,支持Html和Markdown

Animation effects to text, not really textview

Quick Overview

ExpandableTextView is an Android library that provides a custom TextView capable of expanding and collapsing its content. It allows developers to display long text content in a compact form, with the option for users to expand and read the full text. This library is particularly useful for displaying lengthy descriptions or comments in a space-efficient manner.

Pros

  • Easy integration with existing Android projects
  • Customizable appearance and behavior
  • Smooth animation when expanding and collapsing
  • Supports both programmatic and XML-based configuration

Cons

  • Limited to text content only (no support for rich media)
  • May not be suitable for very large blocks of text
  • Requires additional setup compared to standard TextView
  • Last updated in 2017, potentially lacking support for newer Android features

Code Examples

  1. Basic usage in XML layout:
<com.ms.square.android.expandabletextview.ExpandableTextView
    android:id="@+id/expand_text_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    expandableTextView:maxCollapsedLines="4"
    expandableTextView:animDuration="200">
    <TextView
        android:id="@id/expandable_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/long_text" />
    <ImageButton
        android:id="@id/expand_collapse"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right|bottom"
        android:background="@android:color/transparent"
        android:src="@drawable/ic_expand_more_black_24dp" />
</com.ms.square.android.expandabletextview.ExpandableTextView>
  1. Programmatically setting text:
val expandableTextView = findViewById<ExpandableTextView>(R.id.expand_text_view)
expandableTextView.text = "This is a long text that will be expandable..."
  1. Listening for expand/collapse events:
expandableTextView.setOnExpandStateChangeListener { textView, isExpanded ->
    Log.d("ExpandableTextView", "Text is ${if (isExpanded) "expanded" else "collapsed"}")
}

Getting Started

  1. Add the dependency to your build.gradle file:
dependencies {
    implementation 'com.ms-square:expandabletextview:0.1.4'
}
  1. Add the ExpandableTextView to your layout XML:
<com.ms.square.android.expandabletextview.ExpandableTextView
    android:id="@+id/expand_text_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    expandableTextView:maxCollapsedLines="4"
    expandableTextView:animDuration="200">
    <!-- Child views here -->
</com.ms.square.android.expandabletextview.ExpandableTextView>
  1. In your Activity or Fragment, you can now use the ExpandableTextView:
val expandableTextView = findViewById<ExpandableTextView>(R.id.expand_text_view)
expandableTextView.text = "Your long text here..."

Competitor Comparisons

RichEditor for Android is a beautiful Rich Text WYSIWYG Editor for Android.

Pros of richeditor-android

  • Offers rich text editing capabilities with formatting options like bold, italic, underline, etc.
  • Supports image insertion and manipulation within the editor
  • Provides a WYSIWYG interface for creating formatted content

Cons of richeditor-android

  • More complex implementation and potentially larger codebase
  • May have a steeper learning curve for developers
  • Could be overkill for simple text expansion scenarios

Code Comparison

ExpandableTextView:

ExpandableTextView textView = (ExpandableTextView) findViewById(R.id.expandable_text_view);
textView.setText("Your long text here");
textView.setOnExpandStateChangeListener(new ExpandableTextView.OnExpandStateChangeListener() {
    @Override
    public void onExpandStateChanged(TextView textView, boolean isExpanded) {
        // Handle expand/collapse state change
    }
});

richeditor-android:

RichEditor editor = (RichEditor) findViewById(R.id.editor);
editor.setEditorHeight(200);
editor.setEditorFontSize(22);
editor.setEditorFontColor(Color.RED);
editor.setPadding(10, 10, 10, 10);

ExpandableTextView is focused on expanding and collapsing long text content, making it simpler to implement for basic text expansion needs. richeditor-android, on the other hand, provides a full-featured rich text editor with various formatting options, making it more suitable for complex content creation scenarios but potentially more challenging to integrate and customize.

:page_facing_up: Android Text Full Jusiftication / Wrapping / Justify / Hyphenate - V2.0

Pros of TextJustify-Android

  • Offers text justification functionality, which ExpandableTextView doesn't provide
  • Supports hyphenation for better text alignment
  • Allows for custom text layouts and advanced text rendering

Cons of TextJustify-Android

  • Less focused on expandable/collapsible text functionality
  • May have a steeper learning curve due to more complex features
  • Last updated in 2017, potentially outdated compared to ExpandableTextView

Code Comparison

ExpandableTextView:

ExpandableTextView textView = findViewById(R.id.expandable_text_view);
textView.setText("Long text here...");
textView.setOnExpandStateChangeListener(new ExpandableTextView.OnExpandStateChangeListener() {
    @Override
    public void onExpandStateChanged(TextView textView, boolean isExpanded) {
        // Handle expand/collapse state change
    }
});

TextJustify-Android:

TextViewEx textView = findViewById(R.id.text_view);
textView.setText("Long text here...", true);
textView.setTextColor(Color.BLACK);
textView.setLineSpacing(0);
textView.setAlignment(TextViewEx.TextAlign.JUSTIFY);

Both libraries offer custom TextView implementations, but they focus on different aspects. ExpandableTextView provides a simple way to create expandable/collapsible text views, while TextJustify-Android offers more advanced text rendering options, including justification and hyphenation. The choice between the two depends on the specific requirements of your project.

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

Pros of android-autofittextview

  • Automatically adjusts text size to fit within the bounds of the TextView
  • Supports multiple lines of text
  • Maintains the original text content without truncation

Cons of android-autofittextview

  • Doesn't provide expandable functionality
  • May result in very small text sizes for long content
  • Limited customization options for text resizing behavior

Code Comparison

ExpandableTextView:

ExpandableTextView expandableTextView = findViewById(R.id.expandable_text_view);
expandableTextView.setText("Long text content...");
expandableTextView.setOnExpandStateChangeListener(new ExpandableTextView.OnExpandStateChangeListener() {
    @Override
    public void onExpandStateChanged(TextView textView, boolean isExpanded) {
        // Handle expand/collapse state change
    }
});

android-autofittextview:

AutofitTextView autofitTextView = findViewById(R.id.autofit_text_view);
autofitTextView.setText("Long text content...");
autofitTextView.setMaxLines(3);
autofitTextView.setMinTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
autofitTextView.setMaxTextSize(TypedValue.COMPLEX_UNIT_SP, 18);

The main difference in usage is that ExpandableTextView focuses on expanding/collapsing text, while android-autofittextview automatically resizes text to fit within the view's bounds. ExpandableTextView offers more control over the expand/collapse behavior, while android-autofittextview provides a simpler solution for fitting text within a constrained space.

Android平台下的富文本解析器,支持Html和Markdown

Pros of RichText

  • Supports a wider range of rich text features, including images, links, and custom spans
  • Offers better performance for complex text rendering
  • Provides more customization options for text styling and formatting

Cons of RichText

  • More complex to implement and configure compared to ExpandableTextView
  • May have a steeper learning curve for developers new to rich text handling
  • Potentially larger library size due to additional features

Code Comparison

ExpandableTextView:

ExpandableTextView textView = findViewById(R.id.expandable_text_view);
textView.setText("Your long text here");
textView.setOnExpandStateChangeListener(new ExpandableTextView.OnExpandStateChangeListener() {
    @Override
    public void onExpandStateChanged(TextView textView, boolean isExpanded) {
        // Handle expand/collapse state change
    }
});

RichText:

RichText.fromHtml("<p>Your <b>rich</b> text <i>here</i></p>")
    .imageGetter(new ImageGetter() {
        @Override
        public Drawable getDrawable(String source) {
            // Load and return image drawable
        }
    })
    .into(textView);

The code comparison shows that RichText offers more advanced text handling capabilities, while ExpandableTextView focuses on expandable/collapsible functionality for long text.

Animation effects to text, not really textview

Pros of HTextView

  • Offers a variety of text animation effects, including fade, scale, evaporate, and more
  • Supports custom typefaces and text styles
  • Provides a rich set of customization options for animations

Cons of HTextView

  • Focuses primarily on text animations, lacking expandable/collapsible functionality
  • May have higher performance overhead due to complex animations
  • Less suitable for long text content or expandable descriptions

Code Comparison

ExpandableTextView:

ExpandableTextView textView = findViewById(R.id.expandable_text_view);
textView.setText("Long text content...");
textView.setOnExpandStateChangeListener(new ExpandableTextView.OnExpandStateChangeListener() {
    @Override
    public void onExpandStateChanged(TextView textView, boolean isExpanded) {
        // Handle expand/collapse state change
    }
});

HTextView:

HTextView hTextView = findViewById(R.id.h_text_view);
hTextView.setAnimateType(HTextViewType.SCALE);
hTextView.animateText("Animated text");

ExpandableTextView is designed for expanding and collapsing long text content, while HTextView focuses on applying various text animations. ExpandableTextView is more suitable for displaying lengthy descriptions or articles, whereas HTextView excels in creating eye-catching text effects for shorter content or headlines. The choice between the two depends on the specific requirements of your application and the desired user experience.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

ExpandableTextView Android Arsenal

ExpandableTextView is an Android library that allows developers to easily create an TextView which can expand/collapse just like the Google Play's app description. Feel free to use it all you want in your Android apps provided that you cite this project.

Quick Demo

Requirements

API Level 8 (Froyo) and above.

Setup

The library is pushed to Maven Central as an AAR, so you just need to add the followings to your build.gradle file:


dependencies {
    compile 'com.ms-square:expandableTextView:0.1.4'
}

Usage

Using the library is really simple, just look at the source code of the provided sample. (Look at the SampleTextListAdapter.java for the use within a ListView)

The important thing to note is that the view Ids for TextView and ImageButton must be set to "@id/expandable_text" and "@id/expand_collapse" respectively for this library to work.

Also, you can optionally set the following attributes in your layout xml file to customize the behavior of the ExpandableTextView.

  • maxCollapsedLines (defaults to 8) The maximum number of text lines allowed to be shown when the TextView gets collapsed

  • animDuration (defaults to 300ms) Duration of the Animation for the expansion/collapse

  • animAlphaStart (defaults to 0.7f) Alpha value of the TextView when the animation starts (NOTE) Set this value to 1 if you want to disable the alpha animation.

  • expandDrawable Customize a drawable set to ImageButton to expand the TextView

  • collapseDrawable Customize a drawable set to ImageButton to collapse the TextView

  <!-- sample xml -->
  <com.ms.square.android.expandabletextview.ExpandableTextView
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:expandableTextView="http://schemas.android.com/apk/res-auto"
      android:id="@+id/expand_text_view"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      expandableTextView:maxCollapsedLines="4"
      expandableTextView:animDuration="200">
      <TextView
          android:id="@id/expandable_text"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginLeft="10dp"
          android:layout_marginRight="10dp"
          android:textSize="16sp"
          android:textColor="#666666" />
      <ImageButton
          android:id="@id/expand_collapse"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:padding="16dp"
          android:layout_gravity="right|bottom"
          android:background="@android:color/transparent"/>
  </com.ms.square.android.expandabletextview.ExpandableTextView>
// sample code snippet to set the text content on the ExpandableTextView
ExpandableTextView expTv1 = (ExpandableTextView) rootView.findViewById(R.id.sample1)
                    .findViewById(R.id.expand_text_view);
                    
// IMPORTANT - call setText on the ExpandableTextView to set the text content to display
expTv1.setText(getString(R.string.dummy_text1));

License

Copyright 2014 Manabu Shimobe

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.