Android - Expandable TextView with Animation

后端 未结 15 1067
小蘑菇
小蘑菇 2020-11-28 18:24

I have a TextView which firstly shows a small portion of a long text.

The user can press a \"see more\" button to expand the TextView and s

15条回答
  •  迷失自我
    2020-11-28 19:08

    Cliffus' answer came close to what I was looking for, but it doesn't support using the setMaxLines() method, which causes issues when you can't set the max lines through XML.

    I've forked their library and made it so that using setMaxLines() won't break the expand/collapse action. I also updated the Gradle configuration and migrated it to AndroidX. Otherwise, the usage is the same as before.

    You can include it in your project using Jitpack:

    allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }
    
    dependencies {
        implementation 'com.github.zacharee:Android-ExpandableTextView:Tag'
    }
    

    Where Tag is the latest commit tag (https://jitpack.io/#zacharee/Android-ExpandableTextView/).

    The usage is exactly the same as the original library's. Include the ExpandableTextView in your XML:

    
    

    And expand/collapse in code:

    if (expandable.isExpanded) {
        expandable.collapse()
    else {
        expandable.expand()
    }
    

提交回复
热议问题