'How can i use HTextView scale textview effect (com.hanks.htextview.HTextView) as multiline effect?

At the moment it works with single line and when I input a text with more than one line, the application crashes.

MainActivity:

    HTextView tvQuestion_hanks = (HTextView) findViewById(R.id.tvQs_hanks);
    tvQuestion_hanks.setAnimateType(HTextViewType.SCALE);
    tvQuestion_hanks.animateText("Hello world");

Layout:

    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:htext="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">


         <com.hanks.htextview.HTextView

                android:id="@+id/tvQs_hanks"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                android:layout_marginTop="16dp"
                android:textColor="#000000"
                android:textSize="17dp"
                android:text="Question"
                htext:animateType="scale"
                android:gravity="start">

         </com.hanks.htextview.HTextView>

     </RelativeLayout>

I've tried different layout codes like;

     android:lines="5"
     android:maxLines="5"
     android:nestedScrollingEnabled="true"

but it didn't work . This is my logcat just after i press the button and a multiline text is sent to HTextView (as I said the app crashes) :

            02-13 20:01:18.074 4456-4456/com.example.moham.myapplication D/AndroidRuntime: 
            Shutting down VM
            02-13 20:01:18.074 4456-4456/com.example.moham.myapplication W/dalvikvm: 
            threadid=1: thread exiting with uncaught exception (group=0x94caeb20)
            02-13 20:01:18.074 4456-4456/com.example.moham.myapplication E/AndroidRuntime: 
            FATAL EXCEPTION: main
                                                                           Process: com.example.moham.myapplication, PID: 
           4456
                                                                           java.lang.ArrayIndexOutOfBoundsException: 
           length=100; index=100
                                                                               at 
           com.hanks.htextview.animatetext.HText.prepareAnimate(HText.java:88)
                                                                               at 
           com.hanks.htextview.animatetext.HText.animateText(HText.java:74)
                                                                               at 
           com.hanks.htextview.HTextView.animateText(HTextView.java:107)
                                                                               at 
           com.example.moham.myapplication.MainActivity$1.onClick(MainActivity.java:34)
                                                                               at 
           android.view.View.performClick(View.java:4438)
                                                                               at 
           android.view.View$PerformClick.run(View.java:18422)
                                                                               at 
           android.os.Handler.handleCallback(Handler.java:733)
                                                                               at 
           android.os.Handler.dispatchMessage(Handler.java:95)
                                                                               at android.os.Looper.loop(Looper.java:136)
                                                                               at 
           android.app.ActivityThread.main(ActivityThread.java:5019)
                                                                               at java.lang.reflect.Method.invokeNative(Native 
           Method)
                                                                               at 
           java.lang.reflect.Method.invoke(Method.java:515)
                                                                               at 
           com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
                                                                               at 
           com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
                                                                               at dalvik.system.NativeStart.main(Native 
           Method)

HTextView GitHub page: https://github.com/hanks-zyh/HTextView

HTextView GitHub page2: https://github.com/yikwing/HTextView



Solution 1:[1]

Try this method... It will surely work for you as it's working perfectly for me with multiline text as well...

Thanks me later :)

Animations are a great way to bring life into our app. Animating views are easy, but How to animate text. For animating text (not TextView) we are going to use HTextView a free library available on GitHub.

For this demo app, we have six HTextView and we are animating different texts in all the HTextView. For using HTextView we are going to add HTextView dependencies in-app Gradle file.

build.gradle (Module:App)

def htextview_version = "0.1.2"
compile "com.hanks:htextview-base:$htextview_version"        // base library
compile "com.hanks:htextview-fall:$htextview_version"        // optional
compile "com.hanks:htextview-fade:$htextview_version"        // optional
compile "com.hanks:htextview-line:$htextview_version"        // optional
compile "com.hanks:htextview-rainbow:$htextview_version"     // optional
compile "com.hanks:htextview-typer:$htextview_version"       // optional
compile "com.hanks:htextview-scale:$htextview_version"       // optional
compile "com.hanks:htextview-evaporate:$htextview_version"   // optional

Sync, your project.

Following are the code for activity_main.xml file.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.hanks.htextview.fall.FallTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        android:text=""
        android:id="@+id/textView"
        android:textSize="20sp"
        android:gravity="center"
         />


    <com.hanks.htextview.line.LineTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        android:text=""
        android:id="@+id/textViewLine"
        app:animationDuration="1000"
        android:textSize="20sp"
        app:lineColor="#1367bc"
        app:lineWidth="4dp"
        android:gravity="center"
        />

    <com.hanks.htextview.fade.FadeTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        android:text=""
        android:id="@+id/textViewFade"
        app:animationDuration="1000"
        android:textSize="20sp"
        android:gravity="center"
        />


    <com.hanks.htextview.typer.TyperTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        android:text=""
        android:id="@+id/textViewTyper"
        app:charIncrease="3"
        app:typerSpeed="80"
        android:textSize="20sp"
        android:gravity="center"
        />


    <com.hanks.htextview.rainbow.RainbowTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        android:text=""
        android:id="@+id/textViewRainBow"
        android:textSize="20sp"
        app:colorSpace="150dp"
        app:colorSpeed="4dp"
        android:gravity="center"
        />


    <com.hanks.htextview.scale.ScaleTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        android:text=""
        android:id="@+id/textViewScale"
        android:textSize="20sp"
        android:gravity="center"
        />

</LinearLayout>

In our MainActivity.java file, we are first initializing all the HTextView. We have a String Array for different messages. We are changing all HTextView text with time using String Array. Following is the code for MainActivity.java file...

package com.vlemonn.java.blog.htextview;

import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.hanks.htextview.base.HTextView;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {
    
    private HTextView textView,textViewScale,textViewRainBow,textViewTyper,textViewFade,textViewLine;
    int delay = 2000; //milliseconds
    Handler handler;
    ArrayList<String> arrMessages = new ArrayList<>();
    int position=0;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        /* Some Sample Messages for Animation */
        arrMessages.add("Hello, vLemonn!");
        arrMessages.add("Hello, World!");
        arrMessages.add("Free Android Tutorials");
        arrMessages.add("By Mayank Sanghvi");
        arrMessages.add("@vLemonn");
        arrMessages.add("Subscribe, Share, Like");
        arrMessages.add("Support Us");
        
        /* Initialize HTextView */
        textView = findViewById(R.id.textView);
        textViewScale= findViewById(R.id.textViewScale);
        textViewRainBow= findViewById(R.id.textViewRainBow);
        textViewTyper= findViewById(R.id.textViewTyper);
        textViewFade= findViewById(R.id.textViewFade);
        textViewLine= findViewById(R.id.textViewLine);

        /* First Message */
        textView.animateText(arrMessages.get(position));
        textViewScale.animateText(arrMessages.get(position));
        textViewRainBow.animateText(arrMessages.get(position));
        textViewTyper.animateText(arrMessages.get(position));
        textViewFade.animateText(arrMessages.get(position));
        textViewLine.animateText(arrMessages.get(position));
        position++;
        
        /* Change Messages every 2 Seconds */
        handler = new Handler();
        handler.postDelayed(new Runnable(){
            public void run(){

                handler.postDelayed(this, delay);
                if(position>=arrMessages.size())
                    position=0;
                textView.animateText(arrMessages.get(position));
                textViewScale.animateText(arrMessages.get(position));
                textViewRainBow.animateText(arrMessages.get(position));
                textViewTyper.animateText(arrMessages.get(position));
                textViewFade.animateText(arrMessages.get(position));
                textViewLine.animateText(arrMessages.get(position));
                position++;
            }
        }, delay);

    }
}

Final Demo (Output): Final Demo (Output)

If you find this answer useful then please Accept it so that everyone can use this easily...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1