android自动滚动
A. android linearlayout如何自动滚到底部
方案:
1、需要在LinearLayout外部包裹上ScrollView
2、设置ScrollView滚动到底部
代码示例:
布局示意:
<ScrollView
android:id="@+id/scroll_view">
<LinearLayout>
</LinearLayout>
</ScrollView>
java">java中调用
ScrollViewsv=(ScrollView)findViewById(R.id.scroll_view);//获取scrollView组件
sv.fullScroll(ScrollView.FOCUS_DOWN);//滚动到底部
B. Android实现自动滚动的瀑布流怎么实现
1、酷派手机左边第一个桌面就是瀑布流(新闻桌面),这个其实用处不大,而且更新还费流量。点手机左键,打开桌面管理。
2、此时,会发现除了瀑布流之处。其余的桌面都可以删除。
C. Android 自动滚动的RecyclerView
RecycelrView 自动滚动,顶部item上移动,底部item有动画效果的出来,用于一些条目循环等操作,动漫自动观看
BRVAH官方使用指南(持续更新) -
GitHub - wangtao2855/PictureVideoDemo: RecyerlView自动滚动功能
D. android studio怎么实现字幕自动滚动
这个Android字幕滚动类的自定义功能比较多,可定义当前滚动到结尾时的停顿时间,单位:毫秒,还可设置当前的滚动速度,值越小,速度越快。
主要实现代码如下:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package com.tony.autoscroll;
import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.ScrollView;
/**
* @author Tony
*/
public class AutoScrollView extends ScrollView {
private final Handler handler = new Handler();
private long ration = 50;
private boolean isScrolled = false;
private int currentIndex = 0;
private long period = 1000;
private int currentY = -1;
private double x;
private double y;
private int type = -1;
/**
* @param context
*/
public AutoScrollView(Context context) {
this(context, null);
}
/**
* @param context
* @param attrs
*/
public AutoScrollView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
/**
* @param context
* @param attrs
* @param defStyle
*/
public AutoScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public boolean onTouchEvent(MotionEvent event) {
int Action = event.getAction();
switch (Action) {
case MotionEvent.ACTION_DOWN:
x=event.getX();
y=event.getY();
if (type == 0) {
setScrolled(false);
}
break;
case MotionEvent.ACTION_MOVE:
double moveY = event.getY() - y;
double moveX = event.getX() - x;
Log.d("test", "moveY = " + moveY + " moveX = " + moveX );
if ((moveY>20||moveY<-20) && (moveX < 50 || moveX > -50) && getParent() != null) {
getParent().(true);
}
break;
case MotionEvent.ACTION_UP:
if (type == 0) {
currentIndex = getScrollY();
setScrolled(true);
}
break;
default:
break;
}
return super.onTouchEvent(event);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent p_event)
{
Log.d("test", "onInterceptTouchEvent");
return true;
}
/**
* 判断当前是否为滚动状态
* @return the isScrolled
*/
public boolean isScrolled() {
return isScrolled;
}
/**
* 开启或者关闭自动滚动功能
* @param isScrolled
* true为开启,false为关闭
*/
public void setScrolled(boolean isScrolled) {
this.isScrolled = isScrolled;
autoScroll();
}
/**
* 获取当前滚动到结尾时的停顿时间,单位:毫秒
* @return the period
*/
public long getPeriod() {
return period;
}
/**
* 设置当前滚动到结尾时的停顿时间,单位:毫秒
* @param period
*the period to set
*/
public void setPeriod(long period) {
this.period = period;
}
/**
* 获取当前的滚动速度,单位:毫秒,值越小,速度越快。
* @return the speed
*/
public long getSpeed() {
return ration;
}
/**
* 设置当前的滚动速度,单位:毫秒,值越小,速度越快。
* @param speed
*the ration to set
*/
public void setSpeed(long speed) {
this.ration = speed;
}
public void setType(int type){
this.type = type;
}
private void autoScroll() {
handler.postDelayed(new Runnable() {
@Override
public void run() {
boolean flag = isScrolled;
if (flag) {
//Log.d("test", "currentY = " + currentY + " getScrollY() = "+ getScrollY() );
if (currentY == getScrollY()) {
try {
Thread.sleep(period);
} catch (InterruptedException e) {
e.printStackTrace();
}
currentIndex = 0;
scrollTo(0, 0);
handler.postDelayed(this, period);
} else {
currentY = getScrollY();
handler.postDelayed(this, ration);
currentIndex++;
scrollTo(0, currentIndex * 1);
}
} else {
//currentIndex = 0;
//scrollTo(0, 0);
}
}
}, ration);
}
}
E. android垂直TextView怎么能让它自动滚动
这是跑马灯的效果。实现该功能步骤:
1、自定义Views,继承自TextView。
2、重写onDrow方法,计算每次的滚动的距离。
3、计算view的Y轴的重点,让当前显示的处于高亮显示状态。
4、定时的刷新View使其界面不断的刷先,出现滚动的效果。
5、实现数据结构,将数据传给view。
几个步骤代码可以参考下面
下面看看主要代码:
1、创建一个类继承TextView
/**
*@authorxushilin
*
*垂直滚动的TextViewWidget
*/
2、实现构造函数:
publicVerticalScrollTextView(Contextcontext){
super(context);
init();
}
publicVerticalScrollTextView(Contextcontext,AttributeSetattr){
super(context,attr);
init();
}
publicVerticalScrollTextView(Contextcontext,AttributeSetattr,inti){
super(context,attr,i);
init();
}
privatevoidinit(){
setFocusable(true);
//这里主要处理如果没有传入内容显示的默认值
if(list==null){
list=newArrayList<Notice>();
Noticesen=newNotice(0,"暂时没有通知公告");
list.add(0,sen);
}
//普通文字的字号,以及画笔颜色的设置
mPaint=newPaint();
mPaint.setAntiAlias(true);
mPaint.setTextSize(16);
mPaint.setColor(Color.BLACK);
mPaint.setTypeface(Typeface.SERIF);
//高亮文字的字号,以及画笔颜色的设置
mPathPaint=newPaint();
mPathPaint.setAntiAlias(true);
mPathPaint.setColor(Color.RED);
mPathPaint.setTextSize(16);
mPathPaint.setTypeface(Typeface.SANS_SERIF);
}
3、从写onDraw方法,并计算文字的行距,并且将将普通文字和高亮文字,在这个方法中绘制出来
protectedvoidonDraw(Canvascanvas){
super.onDraw(canvas);
canvas.drawColor(0xEFeffff);
Paintp=mPaint;
Paintp2=mPathPaint;
p.setTextAlign(Paint.Align.CENTER);
if(index==-1)
return;
p2.setTextAlign(Paint.Align.CENTER);
canvas.drawText(list.get(index).getName(),mX,middleY,p2);
floattempY=middleY;
for(inti=index-1;i>=0;i--){
tempY=tempY-DY;
if(tempY<0){
break;
}
canvas.drawText(list.get(i).getName(),mX,tempY,p);
}
tempY=middleY;
for(inti=index+1;i<list.size();i++){
tempY=tempY+DY;
if(tempY>mY){
break;
}
canvas.drawText(list.get(i).getName(),mX,tempY,p);
}
}
4、计算Y轴中值以及更新索引
protectedvoidonSizeChanged(intw,inth,intow,intoh){
super.onSizeChanged(w,h,ow,oh);
mX=w*0.5f;
mY=h;
middleY=h*0.5f;
}
privatelongupdateIndex(intindex){
if(index==-1)
return-1;
this.index=index;
returnindex;
}
5、定时更新view,并将接口暴露给客户程序调用。
publicvoipdateUI(){
newThread(newupdateThread()).start();
}
{
longtime=1000;
inti=0;
publicvoidrun(){
while(true){
longsleeptime=updateIndex(i);
time+=sleeptime;
mHandler.post(mUpdateResults);
if(sleeptime==-1)
return;
try{
Thread.sleep(time);
i++;
if(i==getList().size())
i=0;
}catch(InterruptedExceptione){
e.printStackTrace();
}
}
}
}
HandlermHandler=newHandler();
RunnablemUpdateResults=newRunnable(){
publicvoidrun(){
invalidate();
}
};
6、xml布局文件中调用:
<?xmlversion="1.0"encoding="utf-8"?>
<!--.-->
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<com.demo.xsl.text.SampleView
android:id="@+id/sampleView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/selector"
/>
</LinearLayout>
7、java代码中调用,传递数据:
packagecom.demo.xsl.text;
importjava.util.ArrayList;
importjava.util.List;
importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.os.Handler;
{
SampleViewmSampleView;
@Override
publicvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mSampleView=(SampleView)findViewById(R.id.sampleView1);
Listlst=newArrayList<Sentence>();
for(inti=0;i<30;i++){
if(i%2==0){
Sentencesen=newSentence(i,i+"、金球奖三甲揭晓C罗梅西哈维入围");
lst.add(i,sen);
}else{
Sentencesen=newSentence(i,i+"、公牛欲用三大主力换魔兽?????");
lst.add(i,sen);
}
}
//给View传递数据
mSampleView.setList(lst);
//更新View
mSampleView.updateUI();
}
}
F. 如何让coordinatorlayout自动往上滚动 android
一个自动滚动,轮播循环视图组件。 使用 (1) 引入公共库 引入Android Auto Scroll ViewPager@Github作为你项目的library(如何拉取代码及添加公共库)。 (2) 调用 仅需简单两步: a. 布局定义 <cn.trinea.android.view.autoscrollviewpager.AutoScrollViewPager android:id="@+id/view_pager" android:layout_width="match_parent" android:layout_height="wrap_content" /> 代替一般的ViewPager定义 b. 启动ViewPager自动滚动 startAutoScroll() 启动自动滚动 stopAutoScroll() 停止自动滚动 3、设置 setInterval(long) 设置自动滚动的间隔时间,单位为毫秒 setDirection(int) 设置自动滚动的方向,默认向右 setCycle(boolean) 是否自动循环轮播,默认为true setScrollDurationFactor(double) 设置ViewPager滑动动画间隔时间的倍率,达到减慢动画或改变动画速度的效果 setStopScrollWhenTouch(boolean) 当手指碰到ViewPager时是否停止自动滚动,默认为true setSlideBorderMode(int) 滑动到第一个或最后一个Item的处理方式,支持没有任何操作、轮播以及传递到父View三种模式 setBorderAnimation(boolean) 设置循环滚动时滑动到从边缘滚动到下一个是否需要动画,默认为true 4、其他 (1) 指示器,圆形或是方形指示器请配合ViewPagerIndicator使用 (2)无限循环,如果希望在最后一张继续播放第一张而不是退回到第一张,请参考AutoScrollViewPagerSingleDemo.java,注意这个特性不能和 ViewPagerIndicator 使用。 要是还不能解决? 你来我们群里说吧 这里是开发者互相学习交流的 有大神 让他们给你解释你的疑问 q un号: 1881 68040
G. 安卓开发textview垂直滚动慢
安卓开发textview垂直滚动慢如下,Android TextView可以实现文字平缓垂直自动滚粗银动 ,上面的左右滑动的是AutoHorizontalScrollTextView;下面上下滚动的是AutoVerticalScrollTextView,盯扒上面左右滑动的非常好实凯凳昌现,直接把AutoHorizontalScrollTextView复制到项目中,复制全类名到布局文件中,和系统TextView一样,只需设置文本其他什么都不用设置。
H. android recyclerview 自动滚动什么情况
在工作中有时会遇到含有CheckBox 的ListView/Recyclerview时,发现当初始化CheckBox的状态后, 滚动ListView/Recyclerview,其中CheckBox 的选中状态不停的发生变化。最后发现原因 是ListView/Recyclerview滚动时自动调用 onCheckedChanged 导致的。
I. Android使用ViewPager实现轮播图(自动和手动)
源码链接
效果图
1.自动轮播
2.手动轮播
3.监听点击事件跳转界面
4.每个图片可加标题(我世陆的图片颜色太鲜艳了,就没有让文字显示)
接口回调步骤:
如果界面滚动了,获取当前的item,如果item==0,就设置为最后一个,如果,item==count+1,就设置为告梁第一个,这样可以实现第一个图片和最后一个图片切换时不会出现闪现袜返运或卡顿的画面
这里用到了SparseBooleanArray,它是用来存储布尔值的,类似于key,value,根据其中存放的值来判断是否被选中