又一个SuperTextview

SuperTextViewforAndroid是在TextView基础上扩展了多种动画效果的控件,支持Typewriting、颜色变化等动态样式,并可通过XML布局文件及代码进行配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

SuperTextView for Android 是一个在 TextView 的基础上扩展了几种动画效果的控件。

Gif 展示

Image

 

引入

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

一个功能强大的TextView,可以满足日常大部分布局方式,开发者可已自行组合属性配置出属于自己风格的样式!     基本使用1.添加Gradle依赖    dependencies {     ...     compile 'com.allen.supertextview:supertextview:1.0.1'     }2.布局中如何使用    <com.allen.supertextviewlibrary.SuperTextView             android:id="@ id/super_tv"             android:layout_width="match_parent"             android:layout_height="80dp"             stv:sLeftBottomTextColor2="@color/colorAccent"             stv:sLeftBottomTextString="招商银行(8888)"             stv:sLeftBottomTextString2="限额说明>>"             stv:sLeftIconRes="@drawable/bank_zhao_shang"             stv:sLeftTopTextString="银行卡支付"             stv:sRightCheckBoxRes="@drawable/circular_check_bg"             stv:sRightCheckBoxShow="true"             stv:sLineShow="bottom"              />     注意:             1、上下的线可以通过   sLineShow 设置  有四种显示方式 none,top,bottom,both             2、通过设置 sUseRipple=true 开启水波效果3.代码中如何使用   /**  * 可以通过链式设置大部分常用的属性值  */     superTextView.setLeftIcon(drawable)             .setLeftString("")             .setLeftTVColor(0)             .setLeftTopString("")             .setLeftTopTVColor(0)             .setLeftBottomString("")             .setLeftBottomTVColor(0)             .setLeftBottomString2("")             .setLeftBottomTVColor2(0)             .setRightString("")             .setRightTVColor(0)             .setCbChecked(true)             .setCbBackground(drawable)             .setRightIcon(drawable)             .setRightString("")             .setRightTVColor(0)             .setLeftString("")             .setOnSuperTextViewClickListener(new SuperTextView.OnSuperTextViewClickListener() {                 @Override                 public void onSuperTextViewClick() {                     super.onSuperTextViewClick();                     //do something                 }                 @Override                 public void onLeftTopClick() {                     super.onLeftTopClick();                     //do something                 }                 @Override                 public void onLeftBottomClick() {                     super.onLeftBottomClick();                     //do something                 }                 @Override                 public void onLeftBottomClick2() {                     super.onLeftBottomClick2();                     //do something                 }             });4.点击事件(可根据需求选择实现某个点击事件)    superTextView.setOnSuperTextViewClickListener(new SuperTextView.OnSuperTextViewClickListener() {                 @Override                 public void onSuperTextViewClick() {                     super.onSuperTextViewClick();                     //do something                 }                 @Override                 public void onLeftTopClick() {                     super.onLeftTopClick();                     //do something                 }                 @Override                 public void onLeftBottomClick() {                     super.onLeftBottomClick();                     //do something                 }                 @Override                 public void onLeftBottomClick2() {                     super.onLeftBottomClick2();                     //do something                 }             });5.属性说明(以下属性全部可以通过xml文件配置和代码进行设置)    <declare-styleable name="SuperTextView">     <attr name="sLeftIconRes" format="reference"/>     <attr name="sRightIconRes" format="reference"/>     <attr name="sRightCheckBoxRes" format="reference"/>     <attr name="sLeftTextString" format="string"/>     <attr name="sCenterTextString" format="string"/>     <attr name="sRightTextString" format="string"/>     <attr name="sLeftTopTextString" format="string"/>     <attr name="sLeftBottomTextString" format="string"/>     <attr name="sLeftBottomTextString2" format="string"/>     <attr name="sTopLineMargin" format="dimension"/>     <attr name="sBottomLineMargin" format="dimension"/>     <attr name="sBothLineMargin" format="dimension"/>     <attr name="sLeftIconMarginLeft" format="dimension"/>     <attr name="sLeftTextMarginLeft" format="dimension"/>     <attr name="sLeftTopTextMarginLeft" format="dimension"/>     <attr name="sLeftBottomTextMarginLeft" format="dimension"/>     <attr name="sLeftBottomTextMarginLeft2" format="dimension"/>     <attr name="sRightIconMarginRight" format="dimension"/>     <attr name="sRightTextMarginRight" format="dimension"/>     <attr name="sRightCheckBoxMarginRight" format="dimension"/>     <attr name="sRightCheckBoxShow" format="boolean"/>     <attr name="sIsChecked" format="boolean"/>     <attr name="sUseRipple" format="boolean"/>     <attr name="sLeftTextSize" format="dimension"/>     <attr name="sLeftTopTextSize" format="dimension"/>     <attr name="sLeftBottomTextSize" format="dimension"/>     <attr name="sLeftBottomTextSize2" format="dimension"/>     <attr name="sRightTextSize" format="dimension"/>     <attr name="sCenterTextSize" format="dimension"/>     <attr name="sBackgroundColor" format="color"/>     <attr name="sLeftTextColor" format="color"/>     <attr name="sLeftTopTextColor" format="color"/>     <attr name="sLeftBottomTextColor" format="color"/>     <attr name="sLeftBottomTextColor2" format="color"/>     <attr name="sRightTextColor" format="color"/>     <attr name="sCenterTextColor" format="color"/>     <attr name="sLineShow" format="enum">         <enum name="none" value="0"/>         <enum name="top" value="1"/>         <enum name="bottom" value="2"/>         <enum name="both" value="3"/>     </attr> </declare-styleable>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值