├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── xubo
│ │ └── scrolltext
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── xubo
│ │ │ └── scrolltext
│ │ │ └── DemoActivity.java
│ └── res
│ │ ├── layout
│ │ └── activity_demo.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── xubo
│ └── scrolltext
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── screenshot
└── scrolltextview.gif
├── scrolltextview
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── xubo
│ │ └── scrolltextview
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── xubo
│ │ │ └── scrolltextview
│ │ │ └── ScrollTextView.java
│ └── res
│ │ └── values
│ │ ├── scroll_textview_attrs.xml
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── xubo
│ └── scrolltextview
│ └── ExampleUnitTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | ScrollTextView
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | 1.7
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Android跑马灯式文字滚动
2 | #### 内容分多行滚动
3 | #### 内容只滚动单行
4 | #### 内容单行显示不下自带省略号
5 |
6 |
7 | ## Demo
8 | 
9 |
10 |
11 | ## 方法属性
12 | |方法名|参数|描述|
13 | |:---:|:---:|:---:|
14 | | textColor | color |文字颜色(默认颜色为黑色)
15 | | textSize | dimension |文字大小(默认文字大小为16sp)
16 | | singleLine | boolean |是否单行(默认为单行)
17 | | ellipsis | boolean |单行显示不下时是否带省略号(只在单行模式下有效,默认为单行显示不下带省略号)
18 |
19 |
20 | ## 方法
21 | |属性名|参数类型|描述|
22 | |:---:|:---:|:---:|
23 | | setTextContent | List list |设置滚动内容
24 | | setTextContent | List list, List listeners |设置滚动内容以及内容点击事件
25 | | setTextColor | int textcolor |设置文字颜色
26 | | setTextSize | float textsize |设置文字大小
27 | | startTextScroll | 无 |文字开始自动滚动,初始化会自动调用该方法(适当的时机调用)
28 | | stopTextScroll | 无 |文字暂停滚动(适当的时机调用)
29 |
30 |
31 | ## xml使用例子
32 | ```xml
33 |
43 | ```
44 |
45 | ## 使用
46 | #### gradle
47 | 1.Add it in your root build.gradle at the end of repositories:
48 | ```gradle
49 | allprojects {
50 | repositories {
51 | ...
52 | maven { url "https://jitpack.io" }
53 | }
54 | }
55 | ```
56 | 2.Add the dependency:
57 | ```gradle
58 | dependencies {
59 | compile 'com.github.pirrip90:ScrollTextView:1.0.0'
60 | }
61 | ```
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | applicationId "com.xubo.scrolltext"
9 | minSdkVersion 15
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.2.0'
26 | compile project(':scrolltextview')
27 | }
28 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in E:\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/xubo/scrolltext/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.xubo.scrolltext;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xubo/scrolltext/DemoActivity.java:
--------------------------------------------------------------------------------
1 | package com.xubo.scrolltext;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.widget.Toast;
6 |
7 | import com.xubo.scrolltextview.ScrollTextView;
8 | import com.xubo.scrolltextview.ScrollTextView.OnScrollClickListener;
9 |
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | public class DemoActivity extends AppCompatActivity {
14 |
15 | List list1 = new ArrayList();
16 |
17 | List list2 = new ArrayList();
18 |
19 | List list3 = new ArrayList();
20 |
21 | List listener1 = new ArrayList();
22 |
23 | List listener2 = new ArrayList();
24 |
25 | ScrollTextView text1_stv;
26 |
27 | ScrollTextView text2_stv;
28 |
29 | ScrollTextView text3_stv;
30 |
31 | @Override
32 | protected void onCreate(Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.activity_demo);
35 | setContentView(R.layout.activity_demo);
36 | text1_stv = (ScrollTextView)findViewById(R.id.text1_stv);
37 | text2_stv = (ScrollTextView)findViewById(R.id.text2_stv);
38 | text3_stv = (ScrollTextView)findViewById(R.id.text3_stv);
39 | initData();
40 |
41 | text1_stv.setTextContent(list1, listener1);
42 | text2_stv.setTextContent(list2, listener2);
43 | text3_stv.setTextContent(list3);
44 | }
45 | private void initData()
46 | {
47 | // TODO Auto-generated method stub
48 | list1.add("曼联是英格兰足球史上最为成功的俱乐部之一,也是欧洲乃至世界最具有影响力最成功的的球队之一,共获得20次英格兰顶级联赛冠军,12次英格兰足总杯冠军,4次英格兰联赛杯冠军(除英格兰联赛杯外均为最高纪录)。在欧洲赛场上,曼联共获得3次欧洲冠军联赛冠军,1次欧洲优胜者杯和1次欧洲超级杯冠军。");
49 | list1.add("2008年曼城被来自中东的阿拉伯财团收购,并夺得2010-11赛季英格兰足总杯冠军,成为曼城近三十五年来首个锦标。2011-12赛季,曼城首次夺得英超联赛冠军,时隔44年重新获得英格兰顶级联赛冠军。2013-14赛季,曼城第二次夺得英格兰超级足球联赛冠军,这也是曼城球队历史的第四个顶级联赛冠军。");
50 | listener1.add(new OnScrollClickListener()
51 | {
52 |
53 | @Override
54 | public void onClick()
55 | {
56 | // TODO Auto-generated method stub
57 | Toast.makeText(DemoActivity.this, "a1", Toast.LENGTH_SHORT).show();
58 | }
59 | });
60 | listener1.add(new OnScrollClickListener()
61 | {
62 |
63 | @Override
64 | public void onClick()
65 | {
66 | // TODO Auto-generated method stub
67 | Toast.makeText(DemoActivity.this, "a2", Toast.LENGTH_SHORT).show();
68 | }
69 | });
70 |
71 | list2.add("阿布收购切尔西后斥巨资引援,球队逐渐成为豪门。球队以稳如磐石的防守和铁血精神著称,也以过于防守的“摆大巴”战术而蜚声足坛,是足坛防守反击打法的代表球队之一,也是欧洲乃至世界最具有影响力最成功的球队之一。");
72 | list2.add("利物浦是英格兰足球历史上最成功的俱乐部之一,也是欧洲乃至世界最成功的足球俱乐部之一[1] 。利物浦一共夺取过18次英格兰甲级联赛冠军、7次英格兰足总杯冠军、8次英格兰联赛杯冠军、5次欧洲冠军联赛冠军以及3次欧洲联盟杯冠军,也曾为已解散的G-14创立成员,乃是英格兰历史上最成功的球队之一。");
73 | listener2.add(new OnScrollClickListener()
74 | {
75 |
76 | @Override
77 | public void onClick()
78 | {
79 | // TODO Auto-generated method stub
80 | Toast.makeText(DemoActivity.this, "b1", Toast.LENGTH_SHORT).show();
81 | }
82 | });
83 | listener2.add(new OnScrollClickListener()
84 | {
85 |
86 | @Override
87 | public void onClick()
88 | {
89 | // TODO Auto-generated method stub
90 | Toast.makeText(DemoActivity.this, "b2", Toast.LENGTH_SHORT).show();
91 | }
92 | });
93 |
94 | list3.add("阿森纳是英超上最具规模的俱乐部之一,从俱乐部成立后共夺得13次取得英格兰顶级联赛的冠军,12次英格兰足总杯的冠军,3次英格兰足球超级联赛的冠军,是英格兰顶级足球联赛停留得最久的俱乐部。");
95 | list3.add("热刺是二十世纪首支成为联赛及英格兰足总杯双料冠军的球队。是三支可以连夺两届英格兰足总杯的球队之一,亦是唯一曾两度实现这一成绩的球队。在1963年夺得欧洲优胜者杯宝座,是英国首支取得欧洲赛事锦标的队伍。");
96 | }
97 |
98 | @Override
99 | protected void onRestart()
100 | {
101 | // TODO Auto-generated method stub
102 | super.onRestart();
103 | text1_stv.startTextScroll();
104 | text2_stv.startTextScroll();
105 | text3_stv.startTextScroll();
106 | }
107 |
108 | @Override
109 | protected void onStop()
110 | {
111 | // TODO Auto-generated method stub
112 | super.onStop();
113 | text1_stv.stopTextScroll();
114 | text2_stv.stopTextScroll();
115 | text3_stv.stopTextScroll();
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
15 |
16 |
21 |
22 |
28 |
29 |
40 |
41 |
42 |
47 |
48 |
53 |
54 |
60 |
61 |
72 |
73 |
74 |
79 |
80 |
85 |
86 |
92 |
93 |
104 |
105 |
106 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pirrip90/ScrollTextView/b80f5bb3a8790245ac00b9a9c07de473419c453b/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pirrip90/ScrollTextView/b80f5bb3a8790245ac00b9a9c07de473419c453b/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pirrip90/ScrollTextView/b80f5bb3a8790245ac00b9a9c07de473419c453b/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pirrip90/ScrollTextView/b80f5bb3a8790245ac00b9a9c07de473419c453b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pirrip90/ScrollTextView/b80f5bb3a8790245ac00b9a9c07de473419c453b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ScrollText
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/xubo/scrolltext/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.xubo.scrolltext;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:1.5.0'
9 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pirrip90/ScrollTextView/b80f5bb3a8790245ac00b9a9c07de473419c453b/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Oct 21 11:34:03 PDT 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/screenshot/scrolltextview.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pirrip90/ScrollTextView/b80f5bb3a8790245ac00b9a9c07de473419c453b/screenshot/scrolltextview.gif
--------------------------------------------------------------------------------
/scrolltextview/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/scrolltextview/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | group='com.github.pirrip90'
4 |
5 | android {
6 | compileSdkVersion 23
7 | buildToolsVersion "23.0.2"
8 |
9 | defaultConfig {
10 | minSdkVersion 15
11 | targetSdkVersion 23
12 | versionCode 1
13 | versionName "1.0"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | compile fileTree(dir: 'libs', include: ['*.jar'])
25 | testCompile 'junit:junit:4.12'
26 | compile 'com.android.support:appcompat-v7:23.2.0'
27 | }
28 |
--------------------------------------------------------------------------------
/scrolltextview/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in E:\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/scrolltextview/src/androidTest/java/com/xubo/scrolltextview/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.xubo.scrolltextview;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/scrolltextview/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/scrolltextview/src/main/java/com/xubo/scrolltextview/ScrollTextView.java:
--------------------------------------------------------------------------------
1 | package com.xubo.scrolltextview;
2 |
3 | import android.animation.Animator;
4 | import android.animation.Animator.AnimatorListener;
5 | import android.animation.ValueAnimator;
6 | import android.animation.ValueAnimator.AnimatorUpdateListener;
7 | import android.content.Context;
8 | import android.content.res.TypedArray;
9 | import android.graphics.Canvas;
10 | import android.graphics.Color;
11 | import android.graphics.Paint;
12 | import android.graphics.Paint.FontMetrics;
13 | import android.os.Handler;
14 | import android.util.AttributeSet;
15 | import android.view.View;
16 | import android.view.View.OnClickListener;
17 |
18 | import java.util.ArrayList;
19 | import java.util.HashMap;
20 | import java.util.LinkedList;
21 | import java.util.List;
22 | import java.util.Map;
23 | import java.util.Queue;
24 |
25 | /**
26 | * 类名: ScrollTextView
27 | * 包名:com.xubo.scrolltext.view
28 | * 描述: 滚动的文字View
29 | * 发布版本号:
30 | * 开发人员: 徐波
31 | * 创建时间: 2016年6月15日
32 | */
33 | public class ScrollTextView extends View implements OnClickListener
34 | {
35 | /** 文字默认颜色 */
36 | private static final int TEXT_COLOR = Color.BLACK;
37 |
38 | /** 文字默认大小(单位sp) */
39 | private static final int TEXT_SIZE = 16;
40 |
41 | /** 单行模式 */
42 | private static final boolean SINGLE_LINE = true;
43 |
44 | /** 单行显示不下默认带省略号(单行模式下才有效) */
45 | private static final boolean ELLIPSIS = true;
46 |
47 | /** 文字滚动时间 */
48 | private static final long SCROLL_TIME = 500;
49 |
50 | /** 文字切换时间 */
51 | private static final long CUT_TIME = 3000;
52 |
53 | /** 是否单行模式 */
54 | private boolean isSingleLine;
55 |
56 | /** 单行显示不下是否自带省略号 */
57 | private boolean isEllipsis;
58 |
59 | /** 文字绘制画笔 */
60 | private Paint mPaint;
61 |
62 | /** 文字高度 */
63 | private float mTextHeight;
64 |
65 | /** 文字偏移距离 */
66 | private float mTextOffsetY;
67 |
68 | /** 滚动文字集合 */
69 | private List mContents;
70 |
71 | /** 滚动文字点击监听集合 */
72 | private List mListeners;
73 |
74 | /** 文字信息集合 */
75 | private Queue> mTextInfos;
76 |
77 | /** 省略号信息集合 */
78 | private List mEllipsisTextInfos;
79 |
80 | /** 省略号宽度 */
81 | private float mEllipsisTextWidth;
82 |
83 | /** 滚动的高度 */
84 | private int mTop;
85 |
86 | /** 当前显示的文字信息 */
87 | private List mCurrentTextInfos;
88 |
89 | /** 索引信息集合 */
90 | private Map, OnScrollClickListener> mIndexMap;
91 |
92 | public ScrollTextView(Context context)
93 | {
94 | // TODO Auto-generated constructor stub
95 | this(context, null);
96 | }
97 |
98 | public ScrollTextView(Context context, AttributeSet attrs)
99 | {
100 | // TODO Auto-generated constructor stub
101 | this(context, attrs, 0);
102 | }
103 |
104 | public ScrollTextView(Context context, AttributeSet attrs, int defStyleAttr)
105 | {
106 | super(context, attrs, defStyleAttr);
107 | // TODO Auto-generated constructor stub
108 | TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ScrollTextLayout, defStyleAttr, 0);
109 | int textColor = TEXT_COLOR;
110 | float textSize = sp2px(context, TEXT_SIZE);
111 | if (typedArray != null)
112 | {
113 | textColor = typedArray.getColor(R.styleable.ScrollTextLayout_textColor, textColor);
114 | textSize = typedArray.getDimension(R.styleable.ScrollTextLayout_textSize, textSize);
115 | isSingleLine = typedArray.getBoolean(R.styleable.ScrollTextLayout_singleLine, SINGLE_LINE);
116 | isEllipsis = typedArray.getBoolean(R.styleable.ScrollTextLayout_ellipsis, ELLIPSIS);
117 | }
118 | typedArray.recycle();
119 |
120 | mPaint = new Paint();
121 | mPaint.setColor(textColor);
122 | mPaint.setTextSize(textSize);
123 | mPaint.setAntiAlias(true);
124 |
125 | FontMetrics fontMetrics = mPaint.getFontMetrics();
126 | mTextHeight = fontMetrics.bottom - fontMetrics.top;
127 | mTextOffsetY = -fontMetrics.top;
128 |
129 | mIndexMap = new HashMap, OnScrollClickListener>();
130 | mTextInfos = new LinkedList>();
131 | mEllipsisTextInfos = new ArrayList();
132 |
133 | setOnClickListener(this);
134 | }
135 |
136 | ValueAnimator mValueAnimator;
137 |
138 | Handler mHandler = new Handler();
139 |
140 | Runnable mRunnable = new Runnable()
141 | {
142 |
143 | @Override
144 | public void run()
145 | {
146 | // TODO Auto-generated method stub
147 | if (mTextInfos.size() > 1)
148 | {
149 | mValueAnimator = ValueAnimator.ofFloat(0.0f, -1.0f);
150 | mValueAnimator.setDuration(SCROLL_TIME);
151 | mValueAnimator.addListener(new AnimatorListener()
152 | {
153 |
154 | @Override
155 | public void onAnimationStart(Animator animation)
156 | {
157 | // TODO Auto-generated method stub
158 |
159 | }
160 |
161 | @Override
162 | public void onAnimationRepeat(Animator animation)
163 | {
164 | // TODO Auto-generated method stub
165 |
166 | }
167 |
168 | @Override
169 | public void onAnimationEnd(Animator animation)
170 | {
171 | // TODO Auto-generated method stub
172 | mTop = 0;
173 | mCurrentTextInfos = mTextInfos.poll();
174 | mTextInfos.offer(mCurrentTextInfos);
175 | startTextScroll();
176 | }
177 |
178 | @Override
179 | public void onAnimationCancel(Animator animation)
180 | {
181 | // TODO Auto-generated method stub
182 | mTop = 0;
183 | }
184 | });
185 | mValueAnimator.addUpdateListener(new AnimatorUpdateListener()
186 | {
187 |
188 | @Override
189 | public void onAnimationUpdate(ValueAnimator animation)
190 | {
191 | // TODO Auto-generated method stub
192 | float value = (Float)animation.getAnimatedValue();
193 | mTop = (int)(value * (mTextHeight + getPaddingTop() + getPaddingBottom()));
194 | invalidate();
195 | }
196 |
197 | });
198 | mValueAnimator.start();
199 | }
200 | }
201 | };
202 |
203 | @Override
204 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
205 | {
206 | // TODO Auto-generated method stub
207 | int widthMode = MeasureSpec.getMode(widthMeasureSpec);
208 | int heightMode = MeasureSpec.getMode(heightMeasureSpec);
209 | int measuredWidth = MeasureSpec.getSize(widthMeasureSpec);
210 | int measuredHeight = MeasureSpec.getSize(heightMeasureSpec);
211 |
212 | int textMaxWidth = 0;
213 | if (mContents != null && mContents.size() > 0)
214 | {
215 | textMaxWidth = textTypesetting(measuredWidth - getPaddingLeft() - getPaddingRight(), mContents);
216 | mCurrentTextInfos = mTextInfos.poll();
217 | mTextInfos.offer(mCurrentTextInfos);
218 | }
219 | if (widthMode == MeasureSpec.AT_MOST || widthMode == MeasureSpec.UNSPECIFIED)
220 | {
221 | measuredWidth = textMaxWidth + getPaddingLeft() + getPaddingRight();
222 | }
223 | if (heightMode == MeasureSpec.AT_MOST || heightMode == MeasureSpec.UNSPECIFIED)
224 | {
225 | measuredHeight = (int)(mTextHeight + getPaddingBottom() + getPaddingTop());
226 | }
227 | setMeasuredDimension(measuredWidth, measuredHeight);
228 | startTextScroll();
229 | }
230 |
231 | @Override
232 | protected void dispatchDraw(Canvas canvas)
233 | {
234 | // TODO Auto-generated method stub
235 | super.dispatchDraw(canvas);
236 | if (mCurrentTextInfos != null && mCurrentTextInfos.size() > 0)
237 | {
238 | for (TextInfo textInfo : mCurrentTextInfos)
239 | {
240 | canvas.drawText(textInfo.text,
241 | textInfo.x + getPaddingLeft(),
242 | textInfo.y + getPaddingTop() + mTop,
243 | mPaint);
244 | }
245 | }
246 | if (mTextInfos.size() > 1)
247 | {
248 | List nextTextInfos = mTextInfos.peek();
249 | if (nextTextInfos != null && nextTextInfos.size() > 0)
250 | {
251 | for (TextInfo textInfo : nextTextInfos)
252 | {
253 | canvas.drawText(textInfo.text, textInfo.x + getPaddingLeft(), textInfo.y + getPaddingTop() + mTop
254 | + mTextHeight + getPaddingTop() + getPaddingBottom(), mPaint);
255 | }
256 | }
257 | }
258 | }
259 |
260 | /**
261 | * 描述: 设置滚动内容
262 | * 开发人员:徐波
263 | * 创建时间:2016年6月15日
264 | * @param list 滚动内容集合
265 | */
266 | public void setTextContent(List list)
267 | {
268 | this.mContents = list;
269 | this.mListeners = null;
270 | requestLayout();
271 | invalidate();
272 | }
273 |
274 | /**
275 | * 描述: 设置滚动内容
276 | * 开发人员:徐波
277 | * 创建时间:2016年6月15日
278 | * @param list 滚动内容集合
279 | * @param listener 滚动内容的点击监听集合
280 | */
281 | public void setTextContent(List list, List listener)
282 | {
283 | this.mContents = list;
284 | this.mListeners = listener;
285 | requestLayout();
286 | invalidate();
287 | }
288 |
289 | /**
290 | * 描述: 设置文字颜色
291 | * 开发人员:徐波
292 | * 创建时间:2016年6月15日
293 | * @param color 文字颜色
294 | */
295 | public void setTextColor(int color)
296 | {
297 | mPaint.setColor(color);
298 | invalidate();
299 | }
300 |
301 | /**
302 | * 描述: 设置文字大小
303 | * 开发人员:徐波
304 | * 创建时间:2016年6月15日
305 | * @param size 文字大小
306 | */
307 | public void setTextSize(float size)
308 | {
309 | mPaint.setTextSize(size);
310 | FontMetrics fontMetrics = mPaint.getFontMetrics();
311 | mTextHeight = fontMetrics.bottom - fontMetrics.top;
312 | mTextOffsetY = -fontMetrics.top;
313 | requestLayout();
314 | invalidate();
315 | }
316 |
317 | /**
318 | * 描述: 文字开始自动滚动,初始化会自动调用该方法(适当的时机调用)
319 | * 开发人员:徐波
320 | * 创建时间:2016年6月15日
321 | */
322 | public synchronized void startTextScroll()
323 | {
324 | if (mValueAnimator != null && mValueAnimator.isRunning())
325 | {
326 | mValueAnimator.cancel();
327 | mValueAnimator = null;
328 | }
329 | mHandler.removeCallbacks(mRunnable);
330 | mHandler.postDelayed(mRunnable, CUT_TIME);
331 | }
332 |
333 | /**
334 | * 描述: 文字暂停滚动(适当的时机调用)
335 | * 开发人员:徐波
336 | * 创建时间:2016年6月15日
337 | */
338 | public synchronized void stopTextScroll()
339 | {
340 | if (mValueAnimator != null && mValueAnimator.isRunning())
341 | {
342 | mValueAnimator.cancel();
343 | mValueAnimator = null;
344 | }
345 | mHandler.removeCallbacks(mRunnable);
346 | }
347 |
348 | @Override
349 | public void onClick(View v)
350 | {
351 | // TODO Auto-generated method stub
352 | if (mCurrentTextInfos != null && mListeners != null)
353 | {
354 | OnScrollClickListener onScrollClickListener = mIndexMap.get(mCurrentTextInfos);
355 | if (onScrollClickListener != null)
356 | {
357 | onScrollClickListener.onClick();
358 | }
359 | }
360 | }
361 |
362 | /**
363 | * 描述: 文字排版
364 | * 开发人员:徐波
365 | * 创建时间:2016年6月15日
366 | * @param maxParentWidth
367 | * @param list 排版的滚动文字
368 | * @return 排版文字的宽度
369 | */
370 | private int textTypesetting(float maxParentWidth, List list)
371 | {
372 | // 清空数据及初始化数据
373 | mTextInfos.clear();
374 | mIndexMap.clear();
375 | mEllipsisTextInfos.clear();
376 | mEllipsisTextWidth = 0f;
377 | // 初始化省略号
378 | if (isSingleLine && isEllipsis)
379 | {
380 | String ellipsisText = "...";
381 | for (int i = 0; i < ellipsisText.length(); i++)
382 | {
383 | char ch = ellipsisText.charAt(i);
384 | float[] widths = new float[1];
385 | String srt = String.valueOf(ch);
386 | mPaint.getTextWidths(srt, widths);
387 | TextInfo textInfo = new TextInfo();
388 | textInfo.text = srt;
389 | textInfo.x = mEllipsisTextWidth;
390 | textInfo.y = mTextOffsetY;
391 | mEllipsisTextInfos.add(textInfo);
392 | mEllipsisTextWidth += widths[0];
393 | }
394 | }
395 | // 文字排版
396 | float maxWidth = 0;
397 | // 文字排版最大宽度
398 | float tempMaxWidth = 0f;
399 | int index = 0;
400 | for (String text : list)
401 | {
402 | if (isNullOrEmpty(text))
403 | {
404 | continue;
405 | }
406 | // 排版文字当前的宽度
407 | float textWidth = 0;
408 | // 文字信息集合
409 | List textInfos = new ArrayList();
410 | if (isSingleLine)
411 | {
412 | // 临时文字信息集合
413 | List tempTextInfos = new ArrayList();
414 | // 单行排不下
415 | boolean isLess = false;
416 | // 省略号的起始位置
417 | float ellipsisStartX = 0;
418 | for (int j = 0; j < text.length(); j++)
419 | {
420 | char ch = text.charAt(j);
421 | float[] widths = new float[1];
422 | String srt = String.valueOf(ch);
423 | mPaint.getTextWidths(srt, widths);
424 | TextInfo textInfo = new TextInfo();
425 | textInfo.text = srt;
426 | textInfo.x = textWidth;
427 | textInfo.y = mTextOffsetY;
428 | textWidth += widths[0];
429 | if (textWidth <= maxParentWidth - mEllipsisTextWidth) // 当排版的宽度小于等于最大宽度去除省略号长度时
430 | {
431 | textInfos.add(textInfo);
432 | ellipsisStartX = textWidth;
433 | }
434 | else if (textWidth <= maxParentWidth) // 当排版宽度小于最大宽度时
435 | {
436 | tempTextInfos.add(textInfo);
437 | }
438 | else
439 | // 最大宽度排版不下
440 | {
441 | isLess = true;
442 | break;
443 | }
444 | }
445 | if (isLess)
446 | {
447 | tempMaxWidth = maxParentWidth;
448 | for (TextInfo ellipsisTextInfo : mEllipsisTextInfos)
449 | {
450 | TextInfo textInfo = new TextInfo();
451 | textInfo.text = ellipsisTextInfo.text;
452 | textInfo.x = (ellipsisTextInfo.x + ellipsisStartX);
453 | textInfo.y = ellipsisTextInfo.y;
454 | textInfos.add(textInfo);
455 | }
456 | }
457 | else
458 | {
459 | tempMaxWidth = textWidth;
460 | textInfos.addAll(tempTextInfos);
461 | }
462 | if (tempMaxWidth > maxWidth)
463 | {
464 | maxWidth = tempMaxWidth;
465 | }
466 | mTextInfos.offer(textInfos);
467 | if (mListeners != null && mListeners.size() > index)
468 | {
469 | mIndexMap.put(textInfos, mListeners.get(index));
470 | }
471 | index++;
472 | }
473 | else
474 | {
475 | for (int j = 0; j < text.length(); j++)
476 | {
477 | char ch = text.charAt(j);
478 | float[] widths = new float[1];
479 | String srt = String.valueOf(ch);
480 | mPaint.getTextWidths(srt, widths);
481 | TextInfo textInfo = new TextInfo();
482 | textInfo.text = srt;
483 | textInfo.x = textWidth;
484 | textInfo.y = mTextOffsetY;
485 | textWidth += widths[0];
486 | if (textWidth > maxParentWidth) // 当排版宽度小于最大宽度时
487 | {
488 | tempMaxWidth = maxParentWidth;
489 | mTextInfos.offer(textInfos);
490 | if (mListeners != null && mListeners.size() > index)
491 | {
492 | mIndexMap.put(textInfos, mListeners.get(index));
493 | }
494 |
495 | textInfos = new ArrayList();
496 | textInfo.x = 0;
497 | textInfo.y = mTextOffsetY;
498 | textWidth = widths[0];
499 | }
500 | textInfos.add(textInfo);
501 | }
502 | if (textWidth > tempMaxWidth)
503 | {
504 |
505 | tempMaxWidth = textWidth;
506 | }
507 | mTextInfos.offer(textInfos);
508 | if (tempMaxWidth > maxWidth)
509 | {
510 | maxWidth = tempMaxWidth;
511 | }
512 | if (mListeners != null && mListeners.size() > index)
513 | {
514 | mIndexMap.put(textInfos, mListeners.get(index));
515 | }
516 | index++;
517 | }
518 | }
519 | return (int)maxWidth;
520 | }
521 |
522 | @Override
523 | protected void onDetachedFromWindow()
524 | {
525 | // TODO Auto-generated method stub
526 | super.onDetachedFromWindow();
527 | if (mValueAnimator != null && mValueAnimator.isRunning())
528 | {
529 | mValueAnimator.cancel();
530 | mValueAnimator = null;
531 | }
532 | mHandler.removeCallbacks(mRunnable);
533 | mHandler = null;
534 | }
535 |
536 | /**
537 | * 描述: sp转px
538 | * 开发人员:徐波
539 | * 创建时间:2016年6月15日
540 | * @param context 上下文
541 | * @param spValue sp值
542 | * @return 转换后对应的px值
543 | */
544 | private float sp2px(Context context, float spValue)
545 | {
546 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
547 | return spValue * fontScale;
548 | }
549 |
550 | /**
551 | * 描述: 判断字符串是否为空
552 | * 开发人员:徐波
553 | * 创建时间:2016年6月15日
554 | * @param text
555 | * @return true为空,fale不为空
556 | */
557 | private boolean isNullOrEmpty(String text)
558 | {
559 | if (text == null || "".equals(text.trim()) || text.trim().length() == 0 || "null".equals(text.trim())
560 | || "empty".equals(text))
561 | {
562 | return true;
563 | }
564 | else
565 | {
566 | return false;
567 | }
568 | }
569 |
570 | /**
571 | * 类名: TextInfo
572 | * 包名:com.xubo.scrolltext.view
573 | * 描述: 绘制文字信息
574 | * 发布版本号:
575 | * 开发人员: 徐波
576 | * 创建时间: 2016年6月15日
577 | */
578 | public class TextInfo
579 | {
580 | /** x坐标 */
581 | public float x;
582 |
583 | /** y坐标 */
584 | public float y;
585 |
586 | /** 内容 */
587 | public String text;
588 | }
589 |
590 | /**
591 | * 类名: OnScrollClickListener
592 | * 包名:com.xubo.scrolltext.view
593 | * 描述: 滚动内容点击监听事件
594 | * 发布版本号:
595 | * 开发人员: 徐波
596 | * 创建时间: 2016年6月15日
597 | */
598 | public interface OnScrollClickListener
599 | {
600 | public void onClick();
601 | }
602 | }
603 |
--------------------------------------------------------------------------------
/scrolltextview/src/main/res/values/scroll_textview_attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/scrolltextview/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | scrolltextview
3 |
4 |
--------------------------------------------------------------------------------
/scrolltextview/src/test/java/com/xubo/scrolltextview/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.xubo.scrolltextview;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':scrolltextview'
2 |
--------------------------------------------------------------------------------