SuperTextView for Android 是一个在 TextView 的基础上扩展了几种动画效果的控件。
Gif 展示
引入
Maven:
<dependency>
<groupId>com.king.view</groupId>
<artifactId>supertextview</artifactId>
<version>1.0.1</version>
<type>pom</type>
</dependency>
Gradle:
compile 'com.king.view:supertextview:1.0.1'
引入布局
<android.support.constraint.ConstraintLayout 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"
tools:context="com.king.supertextview.MainActivity">
<com.king.view.supertextview.SuperTextView
android:id="@+id/superTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:minHeight="60dp"
android:lineSpacingMultiplier="1.2"
android:textSize="18sp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="@+id/btn1"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" />
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Normal"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/btn2"
android:layout_marginRight="8dp"
android:onClick="OnClick"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" />
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Typewriting"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
android:onClick="OnClick"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" />
<Button
android:id="@+id/btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ChangeColor"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toRightOf="@+id/btn2"
android:onClick="OnClick"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" />
</android.support.constraint.ConstraintLayout>
代码中设置
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import com.king.view.supertextview.SuperTextView;
public class Main9Activity extends AppCompatActivity {
private SuperTextView superTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main9);
superTextView = (SuperTextView) findViewById(R.id.superTextView);
superTextView.setDynamicText("莫听穿林打叶声,何妨吟啸且徐行。\n竹杖芒鞋轻胜马,谁怕?一蓑烟雨任平生。");
superTextView.setOnDynamicListener(new SuperTextView.OnDynamicListener() {
@Override
public void onChange(int position) {
Log.i("Jenly","onChange:" + position);
}
@Override
public void onCompile() {
Log.i("Jenly","onCompile");
}
});
}
private void clickByDynamicStyle(SuperTextView.DynamicStyle style){
superTextView.setDynamicStyle(style);
superTextView.start();
}
public void OnClick(View v){
switch (v.getId()){
case R.id.btn1:
clickByDynamicStyle(SuperTextView.DynamicStyle.NORMAL);
break;
case R.id.btn2:
clickByDynamicStyle(SuperTextView.DynamicStyle.TYPEWRITING);
break;
case R.id.btn3:
clickByDynamicStyle(SuperTextView.DynamicStyle.CHANGE_COLOR);
break;
}
}
}
原文链接:http://p.codekk.com/detail/Android/jenly1314/SuperTextView