From ac525bd170063e317a041015539905cb8d41b557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8D=A3=E6=B5=A9?= Date: Thu, 21 Sep 2017 18:22:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=8C=85=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 32 ++++++++++++++- .../ExampleInstrumentedTest.java | 2 +- app/src/main/AndroidManifest.xml | 4 +- .../MainActivity.java | 40 +++++++++++++++---- app/src/main/res/layout/activity_main.xml | 16 +++++--- .../ExampleUnitTest.java | 2 +- library/src/main/AndroidManifest.xml | 2 +- .../AutoScrollTextView.java | 2 +- .../autoscrolltextview/IMarqueeListener.java | 2 +- .../autoscrolltextview/MarqueeSwitcher.java | 2 +- .../autoscrolltextview/MarqueeTextView.java | 7 ++-- 11 files changed, 85 insertions(+), 26 deletions(-) rename app/src/androidTest/java/com/{haohahu => haohaohu}/autoscrolltextviewsample/ExampleInstrumentedTest.java (93%) rename app/src/main/java/com/{haohahu => haohaohu}/autoscrolltextviewsample/MainActivity.java (73%) rename app/src/test/java/com/{haohahu => haohaohu}/autoscrolltextviewsample/ExampleUnitTest.java (88%) rename library/src/main/java/com/{haohahu => haohaohu}/autoscrolltextview/AutoScrollTextView.java (99%) rename library/src/main/java/com/{haohahu => haohaohu}/autoscrolltextview/IMarqueeListener.java (80%) rename library/src/main/java/com/{haohahu => haohaohu}/autoscrolltextview/MarqueeSwitcher.java (98%) rename library/src/main/java/com/{haohahu => haohaohu}/autoscrolltextview/MarqueeTextView.java (94%) diff --git a/README.md b/README.md index f0dda32..2089499 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,32 @@ -# AutoScrollTextView +# [AutoScrollTextView](https://github.com/ronghao/FrameAnimationView) [![](https://jitpack.io/v/ronghao/AutoScrollTextView.svg)](https://jitpack.io/#ronghao/AutoScrollTextView) [![](https://travis-ci.org/ronghao/AutoScrollTextView.svg?branch=master)](https://travis-ci.org/ronghao/AutoScrollTextView) [![GitHub license](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://raw.githubusercontent.com/ronghao/CacheManage/master/LICENSE) android 上下滚动播放与走马灯效果结合 + +### 实现原理 ++ 实现上下滚动 + + 使用[ViewSwitcher](https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/widget/ViewSwitcher.java) ++ 使用scrollTo(x,y)和runable循环调用,移动textview,形成走马灯效果 + +# 使用方法 + ++ 使用FrameAnimView控件,继承RecyclingImageView + + FrameAnimView:animSrc="@drawable/anim_loading" ++ 自定义RecyclingImageView控件 + + 参见MyFrameAnimView + + +# 项目添加方法 +在根 build.gradle中添加 + + allprojects { + repositories { + ... + maven { url 'https://jitpack.io' } + } + } +在项目build.gradle中添加 + + dependencies { + compile 'com.github.ronghao:AutoScrollTextView:1.0.0'//版本号参见 + } + +版本号参见![](https://jitpack.io/v/ronghao/AutoScrollTextView.svg) \ No newline at end of file diff --git a/app/src/androidTest/java/com/haohahu/autoscrolltextviewsample/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/haohaohu/autoscrolltextviewsample/ExampleInstrumentedTest.java similarity index 93% rename from app/src/androidTest/java/com/haohahu/autoscrolltextviewsample/ExampleInstrumentedTest.java rename to app/src/androidTest/java/com/haohaohu/autoscrolltextviewsample/ExampleInstrumentedTest.java index ccfd082..266c91d 100644 --- a/app/src/androidTest/java/com/haohahu/autoscrolltextviewsample/ExampleInstrumentedTest.java +++ b/app/src/androidTest/java/com/haohaohu/autoscrolltextviewsample/ExampleInstrumentedTest.java @@ -1,4 +1,4 @@ -package com.haohahu.autoscrolltextviewsample; +package com.haohaohu.autoscrolltextviewsample; import android.content.Context; import android.support.test.InstrumentationRegistry; diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ae875cc..eb8ddca 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ + package="com.haohaohu.autoscrolltextviewsample"> - + diff --git a/app/src/main/java/com/haohahu/autoscrolltextviewsample/MainActivity.java b/app/src/main/java/com/haohaohu/autoscrolltextviewsample/MainActivity.java similarity index 73% rename from app/src/main/java/com/haohahu/autoscrolltextviewsample/MainActivity.java rename to app/src/main/java/com/haohaohu/autoscrolltextviewsample/MainActivity.java index da3feec..da834b9 100644 --- a/app/src/main/java/com/haohahu/autoscrolltextviewsample/MainActivity.java +++ b/app/src/main/java/com/haohaohu/autoscrolltextviewsample/MainActivity.java @@ -1,12 +1,12 @@ -package com.haohahu.autoscrolltextviewsample; +package com.haohaohu.autoscrolltextviewsample; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Toast; -import com.haohahu.autoscrolltextview.AutoScrollTextView; -import com.haohahu.autoscrolltextview.IMarqueeListener; -import com.haohahu.autoscrolltextview.MarqueeTextView; +import com.haohaohu.autoscrolltextview.AutoScrollTextView; +import com.haohaohu.autoscrolltextview.IMarqueeListener; +import com.haohaohu.autoscrolltextview.MarqueeTextView; import java.util.ArrayList; public class MainActivity extends AppCompatActivity { @@ -15,8 +15,10 @@ public class MainActivity extends AppCompatActivity { private MarqueeTextView margueeText1; private MarqueeTextView margueeText2; private AutoScrollTextView autoScrollTextView1; + private AutoScrollTextView autoScrollTextView2; private ArrayList strings; + private ArrayList strings2; @Override protected void onCreate(Bundle savedInstanceState) { @@ -30,10 +32,11 @@ private void init() { findViewById(R.id.main_start_btn).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - //margueeText.postStartScroll(1000); - //margueeText1.postStartScroll(1000); - //margueeText2.postStartScroll(1000); + margueeText.postStartScroll(1000); + margueeText1.postStartScroll(1000); + margueeText2.postStartScroll(1000); autoScrollTextView1.startAutoScroll(); + autoScrollTextView2.startAutoScroll(); } }); @@ -42,7 +45,9 @@ public void onClick(View view) { public void onClick(View view) { margueeText.stopScroll(); margueeText1.stopScroll(); + margueeText2.stopScroll(); autoScrollTextView1.stopAutoScroll(); + autoScrollTextView2.startAutoScroll(); } }); } @@ -92,12 +97,12 @@ public void onFinish() { }); autoScrollTextView1 = (AutoScrollTextView) findViewById(R.id.main_autoscroll_text1); - strings = new ArrayList<>(); strings.add("0走马灯古称蟠螭灯(秦汉)、仙音烛和转鹭灯(唐)、马骑灯(宋),中国特色工艺品,亦是传统节日玩具之一,属于灯笼的一种。"); strings.add("1灯内点上蜡烛,烛产生的热力造成气流,令轮轴转动。轮轴上有剪纸,烛光将剪纸的影投射在屏上,图象便不断走动。"); strings.add("2因多在灯各个面上绘制古代武将骑马的图画,而灯转动时看起来好像几个人你追我赶一样"); strings.add("3因多在灯各个面上绘制古代武将骑马的图画,而灯转动时看起来好像几个人你追我赶一样"); + strings.add("4因多在灯各个图画"); autoScrollTextView1.setTextList(strings); @@ -107,5 +112,24 @@ public void onItemClick(int position) { Toast.makeText(MainActivity.this, strings.get(position), Toast.LENGTH_SHORT).show(); } }); + + autoScrollTextView2 = (AutoScrollTextView) findViewById(R.id.main_autoscroll_text2); + strings2 = new ArrayList<>(); + strings2.add("0走马灯古称蟠螭灯(秦汉)"); + strings2.add("1灯内点上蜡烛,"); + strings2.add("2因多在灯各个面上"); + strings2.add("3因多在灯各个面上"); + strings2.add("4因多在灯各个图画"); + strings2.add(""); + + autoScrollTextView2.setTextList(strings2); + + autoScrollTextView2.setOnItemClickListener(new AutoScrollTextView.OnItemClickListener() { + @Override + public void onItemClick(int position) { + Toast.makeText(MainActivity.this, strings2.get(position), Toast.LENGTH_SHORT) + .show(); + } + }); } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 9d57698..a493877 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -4,7 +4,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context="com.haohahu.autoscrolltextviewsample.MainActivity" + tools:context="com.haohaohu.autoscrolltextviewsample.MainActivity" > - - - - + + diff --git a/app/src/test/java/com/haohahu/autoscrolltextviewsample/ExampleUnitTest.java b/app/src/test/java/com/haohaohu/autoscrolltextviewsample/ExampleUnitTest.java similarity index 88% rename from app/src/test/java/com/haohahu/autoscrolltextviewsample/ExampleUnitTest.java rename to app/src/test/java/com/haohaohu/autoscrolltextviewsample/ExampleUnitTest.java index 1773ce8..0a1a493 100644 --- a/app/src/test/java/com/haohahu/autoscrolltextviewsample/ExampleUnitTest.java +++ b/app/src/test/java/com/haohaohu/autoscrolltextviewsample/ExampleUnitTest.java @@ -1,4 +1,4 @@ -package com.haohahu.autoscrolltextviewsample; +package com.haohaohu.autoscrolltextviewsample; import org.junit.Test; diff --git a/library/src/main/AndroidManifest.xml b/library/src/main/AndroidManifest.xml index 7878d26..b6ebef2 100644 --- a/library/src/main/AndroidManifest.xml +++ b/library/src/main/AndroidManifest.xml @@ -1,5 +1,5 @@ + package="com.haohaohu.autoscrolltextview"> diff --git a/library/src/main/java/com/haohahu/autoscrolltextview/AutoScrollTextView.java b/library/src/main/java/com/haohaohu/autoscrolltextview/AutoScrollTextView.java similarity index 99% rename from library/src/main/java/com/haohahu/autoscrolltextview/AutoScrollTextView.java rename to library/src/main/java/com/haohaohu/autoscrolltextview/AutoScrollTextView.java index 28868f9..bb5b2ab 100644 --- a/library/src/main/java/com/haohahu/autoscrolltextview/AutoScrollTextView.java +++ b/library/src/main/java/com/haohaohu/autoscrolltextview/AutoScrollTextView.java @@ -1,4 +1,4 @@ -package com.haohahu.autoscrolltextview; +package com.haohaohu.autoscrolltextview; import android.content.Context; import android.os.Handler; diff --git a/library/src/main/java/com/haohahu/autoscrolltextview/IMarqueeListener.java b/library/src/main/java/com/haohaohu/autoscrolltextview/IMarqueeListener.java similarity index 80% rename from library/src/main/java/com/haohahu/autoscrolltextview/IMarqueeListener.java rename to library/src/main/java/com/haohaohu/autoscrolltextview/IMarqueeListener.java index 9d13501..2f39af9 100644 --- a/library/src/main/java/com/haohahu/autoscrolltextview/IMarqueeListener.java +++ b/library/src/main/java/com/haohaohu/autoscrolltextview/IMarqueeListener.java @@ -1,4 +1,4 @@ -package com.haohahu.autoscrolltextview; +package com.haohaohu.autoscrolltextview; /** * 走马灯监听 diff --git a/library/src/main/java/com/haohahu/autoscrolltextview/MarqueeSwitcher.java b/library/src/main/java/com/haohaohu/autoscrolltextview/MarqueeSwitcher.java similarity index 98% rename from library/src/main/java/com/haohahu/autoscrolltextview/MarqueeSwitcher.java rename to library/src/main/java/com/haohaohu/autoscrolltextview/MarqueeSwitcher.java index e0ba112..e1e2a96 100644 --- a/library/src/main/java/com/haohahu/autoscrolltextview/MarqueeSwitcher.java +++ b/library/src/main/java/com/haohaohu/autoscrolltextview/MarqueeSwitcher.java @@ -1,4 +1,4 @@ -package com.haohahu.autoscrolltextview; +package com.haohaohu.autoscrolltextview; import android.content.Context; import android.util.AttributeSet; diff --git a/library/src/main/java/com/haohahu/autoscrolltextview/MarqueeTextView.java b/library/src/main/java/com/haohaohu/autoscrolltextview/MarqueeTextView.java similarity index 94% rename from library/src/main/java/com/haohahu/autoscrolltextview/MarqueeTextView.java rename to library/src/main/java/com/haohaohu/autoscrolltextview/MarqueeTextView.java index bc32b32..afb08e1 100644 --- a/library/src/main/java/com/haohahu/autoscrolltextview/MarqueeTextView.java +++ b/library/src/main/java/com/haohaohu/autoscrolltextview/MarqueeTextView.java @@ -1,4 +1,4 @@ -package com.haohahu.autoscrolltextview; +package com.haohaohu.autoscrolltextview; import android.content.Context; import android.graphics.Canvas; @@ -34,8 +34,6 @@ public void run() { postInvalidate(); return; } - currentScrollPos += 1; - scrollTo(currentScrollPos, 0); if (!flag && currentScrollPos >= textWidth - getWidth()) { //currentScrollPos = -getWidth(); flag = true; @@ -45,7 +43,8 @@ public void run() { } if (!flag) { - // 滚动时间间隔 + currentScrollPos += 1; + scrollTo(currentScrollPos, 0); postDelayed(this, speed); } }