package com.liushen.textviewscroll.view;
import android.content.Context;
import android.graphics.Color;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.util.Log;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.liushen.textviewscroll.R;
import com.liushen.textviewscroll.entity.Top;
import java.util.ArrayList;
/**
* Created by liushen on 2016/7/13.
*/
public class ScrollLinearLayout extends LinearLayout {
private Animation animationOut;
private Animation animationIn;
private RoundTextView title;
private TextView content;
private int index;
private boolean scroll;
private ArrayList<Top> tops = new ArrayList<>();
private Context mContext;
public ScrollLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mContext = context;
initView();
}
public ScrollLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
initView();
}
public ScrollLinearLayout(Context context) {
super(context);
mContext = context;
initView();
}
private void initView() {
title = new RoundTextView(mContext);
title.setPadding(dip2px(mContext,5),0,dip2px(mContext,5),0);
LinearLayout.LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
params.rightMargin = dip2px(mContext,10);
title.setTextColor(Color.RED);
title.setStrokeColor(Color.RED);
content = new TextView(mContext);
this.addView(title,params);
this.addView(content);
}
public void setDate(ArrayList<Top> tops) {
this.tops = tops;
title.setText(tops.get(0).getTitle());
content.setText(tops.get(0).getContent());
}
Handler handler = new Handler() {
public void handleMessage(Message msg) {
initAnim();
animationOut.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
title.setText(tops.get(index).getTitle());
content.setText(tops.get(index).getContent());
startAnimation(animationIn);
}
});
startAnimation(animationOut);
super.handleMessage(msg);
}
};
private void initAnim() {
if (animationOut == null) {
animationOut = AnimationUtils.loadAnimation(mContext, R.anim.view_out);
}
if (animationIn == null) {
animationIn = AnimationUtils.loadAnimation(mContext, R.anim.view_in);
}
}
public void start() {
scroll = true;
new Thread(new MyThread()).start();
}
public void pause() {
scroll = false;
}
public class MyThread implements Runnable {
@Override
public void run() {
// TODO Auto-generated method stub
while (scroll) {
try {
Log.i("liushen", "scroll");
Thread.sleep(3000);
if (index < tops.size() - 1) {
index++;
} else {
index = 0;
}
Message message = new Message();
handler.sendMessage(message);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
public int dip2px(Context context, float dipValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dipValue * scale + 0.5f);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
首页通知上下滚动效果
共63个文件
xml:26个
java:7个
bin:6个
4星 · 超过85%的资源 需积分: 50 37 下载量 79 浏览量
2016-07-17
22:05:21
上传
评论
收藏 224KB RAR 举报
温馨提示
首页通知栏上下滚动效果
资源推荐
资源详情
资源评论
收起资源包目录
TextViewScroll.rar (63个子文件)
TextViewScroll
.gitignore 105B
app
.gitignore 8B
build.gradle 653B
src
androidTest
java
com
liushen
textviewscroll
ApplicationTest.java 369B
main
AndroidManifest.xml 685B
res
mipmap-xhdpi
ic_launcher.png 5KB
mipmap-mdpi
ic_launcher.png 2KB
anim
view_out.xml 277B
view_in.xml 276B
layout
activity_main1.xml 1KB
activity_main.xml 1KB
values-w820dp
dimens.xml 364B
mipmap-xxhdpi
ic_launcher.png 8KB
drawable
mipmap-hdpi
ic_launcher.png 3KB
mipmap-xxxhdpi
ic_launcher.png 10KB
values
strings.xml 80B
attrs.xml 356B
colors.xml 214B
dimens.xml 216B
styles.xml 394B
java
com
liushen
textviewscroll
MainActivity.java 4KB
view
ScrollLinearLayout.java 4KB
RoundTextView.java 3KB
entity
Top.java 601B
MainActivity1.java 1KB
test
java
com
liushen
textviewscroll
ExampleUnitTest.java 333B
libs
proguard-rules.pro 662B
app.iml 10KB
settings.gradle 16B
build.gradle 521B
gradlew 5KB
TextViewScroll.iml 945B
gradlew.bat 2KB
gradle.properties 872B
.gradle
2.10
taskArtifacts
fileSnapshots.bin 3.56MB
fileHashes.bin 134KB
outputFileStates.bin 20KB
taskArtifacts.bin 102KB
cache.properties.lock 17B
cache.properties 31B
tasks
_app_compileDebugJavaWithJavac
localClassSetAnalysis
localClassSetAnalysis.lock 17B
localClassSetAnalysis.bin 69KB
localJarClasspathSnapshot
localJarClasspathSnapshot.bin 19KB
localJarClasspathSnapshot.lock 17B
.idea
misc.xml 3KB
encodings.xml 159B
libraries
appcompat_v7_23_2_1.xml 761B
support_v4_23_2_1.xml 903B
junit_4_12.xml 477B
support_vector_drawable_23_2_1.xml 640B
hamcrest_core_1_3.xml 526B
support_annotations_23_2_1.xml 495B
animated_vector_drawable_23_2_1.xml 645B
workspace.xml 165KB
gradle.xml 739B
copyright
profiles_settings.xml 76B
runConfigurations.xml 564B
compiler.xml 686B
.name 14B
modules.xml 365B
gradle
wrapper
gradle-wrapper.properties 231B
gradle-wrapper.jar 52KB
local.properties 427B
共 63 条
- 1
资源评论
- 一小风一2018-08-01可以使用,谢谢分享。
- u0107712512018-08-23能用,但不够强大
刘婶
- 粉丝: 33
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功