Skip to content

Commit

Permalink
修改包名
Browse files Browse the repository at this point in the history
  • Loading branch information
ronghao committed Sep 21, 2017
1 parent 8c44d08 commit ac525bd
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 26 deletions.
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.haohahu.autoscrolltextviewsample;
package com.haohaohu.autoscrolltextviewsample;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.haohahu.autoscrolltextviewsample">
package="com.haohaohu.autoscrolltextviewsample">

<application
android:allowBackup="true"
Expand All @@ -9,7 +9,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.haohahu.autoscrolltextviewsample.MainActivity">
<activity android:name="com.haohaohu.autoscrolltextviewsample.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -15,8 +15,10 @@ public class MainActivity extends AppCompatActivity {
private MarqueeTextView margueeText1;
private MarqueeTextView margueeText2;
private AutoScrollTextView autoScrollTextView1;
private AutoScrollTextView autoScrollTextView2;

private ArrayList<String> strings;
private ArrayList<String> strings2;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -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();
}
});

Expand All @@ -42,7 +45,9 @@ public void onClick(View view) {
public void onClick(View view) {
margueeText.stopScroll();
margueeText1.stopScroll();
margueeText2.stopScroll();
autoScrollTextView1.stopAutoScroll();
autoScrollTextView2.startAutoScroll();
}
});
}
Expand Down Expand Up @@ -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);

Expand All @@ -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();
}
});
}
}
16 changes: 11 additions & 5 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>

<TextView
Expand All @@ -31,29 +31,35 @@
android:orientation="vertical"
>

<com.haohahu.autoscrolltextview.MarqueeTextView
<com.haohaohu.autoscrolltextview.MarqueeTextView
android:id="@+id/main_marguee_text"
android:layout_width="match_parent"
android:layout_height="20dp"
/>

<com.haohahu.autoscrolltextview.MarqueeTextView
<com.haohaohu.autoscrolltextview.MarqueeTextView
android:id="@+id/main_marguee_text1"
android:layout_width="200dp"
android:layout_height="20dp"
/>

<com.haohahu.autoscrolltextview.MarqueeTextView
<com.haohaohu.autoscrolltextview.MarqueeTextView
android:id="@+id/main_marguee_text2"
android:layout_width="200dp"
android:layout_height="20dp"
/>

<com.haohahu.autoscrolltextview.AutoScrollTextView
<com.haohaohu.autoscrolltextview.AutoScrollTextView
android:id="@+id/main_autoscroll_text1"
android:layout_width="match_parent"
android:layout_height="20dp"
/>

<com.haohaohu.autoscrolltextview.AutoScrollTextView
android:id="@+id/main_autoscroll_text2"
android:layout_width="match_parent"
android:layout_height="20dp"
/>
</LinearLayout>


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.haohahu.autoscrolltextviewsample;
package com.haohaohu.autoscrolltextviewsample;

import org.junit.Test;

Expand Down
2 changes: 1 addition & 1 deletion library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.haohahu.autoscrolltextview">
package="com.haohaohu.autoscrolltextview">

<application
android:supportsRtl="true">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.haohahu.autoscrolltextview;
package com.haohaohu.autoscrolltextview;

import android.content.Context;
import android.os.Handler;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.haohahu.autoscrolltextview;
package com.haohaohu.autoscrolltextview;

/**
* 走马灯监听
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.haohahu.autoscrolltextview;
package com.haohaohu.autoscrolltextview;

import android.content.Context;
import android.util.AttributeSet;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.haohahu.autoscrolltextview;
package com.haohaohu.autoscrolltextview;

import android.content.Context;
import android.graphics.Canvas;
Expand Down Expand Up @@ -34,8 +34,6 @@ public void run() {
postInvalidate();
return;
}
currentScrollPos += 1;
scrollTo(currentScrollPos, 0);
if (!flag && currentScrollPos >= textWidth - getWidth()) {
//currentScrollPos = -getWidth();
flag = true;
Expand All @@ -45,7 +43,8 @@ public void run() {
}

if (!flag) {
// 滚动时间间隔
currentScrollPos += 1;
scrollTo(currentScrollPos, 0);
postDelayed(this, speed);
}
}
Expand Down

0 comments on commit ac525bd

Please sign in to comment.