android自动循环滚动
‘壹’ 安卓系统桌面循环滚动桌面设置的
1、手机设置”的“辅助功能”中有选择是否“桌面循环”。
2、在原生的android源码上添加这一功能。
思路:先把界面做出来,再将是否选择的值存到系统的(adb shell进入)data/data/com.android.providers.settings/databases/settings.db数据库中的system表中,
然后在Launch2的源码中取得数据库中是否选择循环桌面来执行相关代码。
先做UI:
在settings源码中的accessibility_settings.xml文件中添加一个checkbox:
java代码
android:key="launch_repeat"
android:title="@string/launch_repeat_title"
android:persistent="false"/>
在settings源码的res中添加相关的代码:
在values/string.xml中添加(英文显示):
Launch Repeat
在values-zh-rCN/string.xml中添加(中文显示):
"循环桌面"
在settings源码的AccessibilitySettings.java中的OnCreate中添加:
java代码
/*****************************************/
mLaunchRepeat=(CheckBoxPreference) findPreference(
LAUNCH_REPEAT);
int LaunchRepeat=Settings.System.getInt(this.getContentResolver(),
"launch_repeat",0);//取出是否被选择
if(LaunchRepeat==1)//如果被选择,那么下次打开setting时就勾选
mLaunchRepeat.setChecked(true);
else
mLaunchRepeat.setChecked(false);//如果没被选择,那么下次打开setting时就不勾选
/*****************************************/
当然还要定义几个量:
private final String LAUNCH_REPEAT =
"launch_repeat";
private CheckBoxPreference mLaunchRepeat;
在onPreferenceTreeClick函数中添加:
java代码
//add by xxnan
if(LAUNCH_REPEAT.equals(key))
{
Settings.System.putInt(getContentResolver(),
"launch_repeat",
((CheckBoxPreference) preference).isChecked()?
1:0);//将是否选择存到系统的system表中
}
//add by xxnan
如果做好了之后当点击选择“桌面循环时”可以到(adb shell进入)data/data/com.android.providers.settings/databases下的settings.db数据库(sqlite3 settings.db)的system
表中看到33|launch_repeat|1(select * from system;)。
到这里就完成了将数据存到系统system表中以及UI,接下来就是在Launch2源码中去取这个值(是否循环)。
到Launcher2源码中去找到Workspace.java文件,在里面有相应的修改:
在onTouchEvent中,之前有修改循环,如下:
java代码
case MotionEvent.ACTION_UP:
if (mTouchState == TOUCH_STATE_SCROLLING) {
final VelocityTracker velocityTracker = mVelocityTracker;
velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
final int velocityX = (int)
velocityTracker.getXVelocity(mActivePointerId);
final int screenWidth = getWidth();
final int whichScreen = (mScrollX + (screenWidth / 2)) / screenWidth;
final float scrolledPos = (float) mScrollX / screenWidth;
Log.i("velocityX","velocityX="+velocityX+"whichScreen="+whichScreen);
/***********************************************/
//modifided by xxnan
if (velocityX > SNAP_VELOCITY) {
// Fling hard enough to move left.
// Don't fling across more than one screen at a time.
Log.i("numscreen","numscreen="+mCurrentScreen);
/* final int bound = scrolledPos < whichScreen ?
( (mCurrentScreen+ getChildCount()) - 1 )% getChildCount():
mCurrentScreen;*/
final int bound =( (mCurrentScreen+ getChildCount()) - 1 )% getChildCount()
;
Log.i("numscreen","bound="+bound);
snapToScreen( bound, velocityX, true);
} else if (velocityX < -SNAP_VELOCITY ) {
// Fling hard enough to move right
// Don't fling across more than one screen at a time.
/*final int bound = scrolledPos > whichScreen ?
( mCurrentScreen + 1 )% getChildCount(): mCurrentScreen;*/
final int bound = ( mCurrentScreen + 1 )% getChildCount() ;
snapToScreen(bound, velocityX, true);
} else {
snapToScreen(whichScreen, 0, true);
}
/***********************************************/
//下面是原生代码
/*if (velocityX > SNAP_VELOCITY && mCurrentScreen > 0) {
// Fling hard enough to move left.
// Don't fling across more than one screen at a time.
final int bound = scrolledPos < whichScreen ?
mCurrentScreen - 1 : mCurrentScreen;
snapToScreen(Math.min(whichScreen, bound), velocityX, true);
} else if (velocityX < -SNAP_VELOCITY && mCurrentScreen <
getChildCount() - 1) {
// Fling hard enough to move right
// Don't fling across more than one screen at a time.
final int bound = scrolledPos > whichScreen ?
mCurrentScreen + 1 : mCurrentScreen;
snapToScreen(Math.max(whichScreen, bound), velocityX, true);
} else {
snapToScreen(whichScreen, 0, true);
}*/
}
mTouchState = TOUCH_STATE_REST;
mActivePointerId = INVALID_POINTER;
releaseVelocityTracker();
break;
那么就要在修改的地方加一个判断,如果system中取得的值是1,就可以循环,如果是0,就不能。
代码修改如下:
java代码
case MotionEvent.ACTION_UP:
if (mTouchState == TOUCH_STATE_SCROLLING) {
final VelocityTracker velocityTracker = mVelocityTracker;
velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
final int velocityX = (int)
velocityTracker.getXVelocity(mActivePointerId);
final int screenWidth = getWidth();
final int whichScreen = (mScrollX + (screenWidth / 2)) / screenWidth;
final float scrolledPos = (float) mScrollX / screenWidth;
Log.i("velocityX","velocityX="+velocityX+"whichScreen="+whichScreen);
/***********************************************/
//modifided by xxnan 2013-1-9
launch_repeat=Settings.System.getInt(mContext.getContentResolver(),
"launch_repeat",0);//取出system表中“launch_repeat”的值
Log.i(" launch_repeat"," launch_repeat="+ launch_repeat);
if(launch_repeat==1)//如果是1,就循环,也就是之前已经改好的
{
if (velocityX > SNAP_VELOCITY) {
// Fling hard enough to move left.
// Don't fling across more than one screen at a time.
Log.i("numscreen","numscreen="+mCurrentScreen);
/* final int bound = scrolledPos < whichScreen ?
( (mCurrentScreen+ getChildCount()) - 1 )% getChildCount():
mCurrentScreen;*/
final int bound =( (mCurrentScreen+ getChildCount()) - 1 )% getChildCount()
;
Log.i("numscreen","bound="+bound);
snapToScreen( bound, velocityX, true);
} else if (velocityX < -SNAP_VELOCITY ) {
// Fling hard enough to move right
// Don't fling across more than one screen at a time.
/*final int bound = scrolledPos > whichScreen ?
( mCurrentScreen + 1 )% getChildCount(): mCurrentScreen;*/
final int bound = ( mCurrentScreen + 1 )% getChildCount() ;
snapToScreen(bound, velocityX, true);
} else {
snapToScreen(whichScreen, 0, true);
}
}
else//如果是0,那么就是原生代码,不循环
{
if (velocityX > SNAP_VELOCITY && mCurrentScreen > 0) {
// Fling hard enough to move left.
// Don't fling across more than one screen at a time.
final int bound = scrolledPos < whichScreen ?
mCurrentScreen - 1 : mCurrentScreen;
snapToScreen(Math.min(whichScreen, bound), velocityX, true);
} else if (velocityX < -SNAP_VELOCITY && mCurrentScreen <
getChildCount() - 1) {
// Fling hard enough to move right
// Don't fling across more than one screen at a time.
final int bound = scrolledPos > whichScreen ?
mCurrentScreen + 1 : mCurrentScreen;
snapToScreen(Math.max(whichScreen, bound), velocityX, true);
} else {
snapToScreen(whichScreen, 0, true);
}
}
/***********************************************/
//下面是原生代码
/*if (velocityX > SNAP_VELOCITY && mCurrentScreen > 0) {
// Fling hard enough to move left.
// Don't fling across more than one screen at a time.
final int bound = scrolledPos < whichScreen ?
mCurrentScreen - 1 : mCurrentScreen;
snapToScreen(Math.min(whichScreen, bound), velocityX, true);
} else if (velocityX < -SNAP_VELOCITY && mCurrentScreen <
getChildCount() - 1) {
// Fling hard enough to move right
// Don't fling across more than one screen at a time.
final int bound = scrolledPos > whichScreen ?
mCurrentScreen + 1 : mCurrentScreen;
snapToScreen(Math.max(whichScreen, bound), velocityX, true);
} else {
snapToScreen(whichScreen, 0, true);
}*/
}
mTouchState = TOUCH_STATE_REST;
mActivePointerId = INVALID_POINTER;
releaseVelocityTracker();
break;
当然这里面也要定义几个量,以及导入几个包:
导入包:
//add by xxnan
import android.content.ContentResolver;//从system表中取数据
import android.provider.Settings;
定义变量:
private int launch_repeat;//取得是否循环的值
到这里就全部修改好了,还有就是编译一下源码中的package/apps的Launch2和Settings的源码,将生成的out/target/。。。/system/app下的
Launch2.apk和Settings.apk替换手机里system/app的这两个apk就可以了。
‘贰’ 怎么在手机桌面设置可以循环滚动的文字,可以自定义的
分析如下:
下载个LED显示屏,手机应用中心搜索LED字母就会出现很多个三方软件,然后你下载就可以使用了。
例如下载个文字锁屏或者LED Scroller。
拓展资料
文字锁屏,Android平台上最有趣的、最美的DIY锁屏,DIY各种纹字锁屏方式,自定义文字图片,搭配编辑精心推荐壁纸,添加各类趣味插件(时间、文字、正计时倒计时等),最简单的DIY方式打造最个性的手机锁屏精灵,真正做到实惠到家的锁屏软件。
(资料来源:网络:文字锁屏)
‘叁’ android开发图片(ImageView)要实现循环匀速滚动,速度可调,怎么实现呢,用什么组件好呢
采用画廊视图,GalleryView,自动匀速定时切换的话可以使用Timetask。网上搜一搜,很多案例。望采纳。
‘肆’ android 如何让gallery自动滚动
让gallery自动滚动可以通过以下两种方法实现:
一、使用Timer和TimerTask类来完成图片的自动定时滚动:
思路:循环调用Gallery类的onFling()方法。
代码:
<span style="white-space:pre"> </span>task = new TimerTask() {
@Override
public void run() {
/**
* 参数1和2:手指在gallery上的动作
* 参数3和4:x方向和y方向的滚动的速度,-数表示向左滚,+数表示向右
*/
gallery.onFling(null, null, -750, 0);
}
};
timer.schele(task, 1000, 5000);
<span style="font-size:32px;"><strong>
</strong></span>
<span style="font-size:32px;"><strong>方式2:</strong></span>
二、使用Handler消息机制完成
思路:子线程内死循环使用handler每隔多长时间向主线程发送消息,通知gallery改变位置。
代码:
子线程部分:
<span style="white-space:pre"> new Thread(new Runnable() {
<span style="white-space:pre"> </span>int flag = 1;
<span style="white-space:pre"> </span>@Override
<span style="white-space:pre"> </span>public void run() {
<span style="white-space:pre"> </span>while (isalive) {
<span style="white-space:pre"> </span>//images为装图片的集合
<span style="white-space:pre"> </span>if ((cur_index + 1) == images.size()) {
<span style="white-space:pre"> </span>flag = -1;
<span style="white-space:pre"> </span>} else if (cur_index == 0) {
<span style="white-space:pre"> </span>flag = 1;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>Message msg = handler.obtainMessage(MSG_UPDATE, cur_index,
<span style="white-space:pre"> </span>0);
<span style="white-space:pre"> </span>handler.sendMessage(msg);
<span style="white-space:pre"> </span>try {
<span style="white-space:pre"> </span>Thread.sleep(4000);
<span style="white-space:pre"> </span>} catch (InterruptedException e) {
<span style="white-space:pre"> </span>e.printStackTrace();
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>switch (flag) {
<span style="white-space:pre"> </span>case 1:
<span style="white-space:pre"> </span>cur_index++;
<span style="white-space:pre"> </span>break;
<span style="white-space:pre"> </span>case -1:
<span style="white-space:pre"> </span>cur_index--;
<span style="white-space:pre"> </span>break;
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>}).start();</span>
主线程部分:
private Handler handler = new Handler() {
public void handleMessage(Message msg) {
if (msg.what == MSG_UPDATE) {
gallery.setSelection(msg.arg1);
}
}
};
两种方式的优缺点:
优点:
使用方式1来实现,效果和手指拖动的效果一样,滚动速度可以自己调。
使用方式2来实现,可以使用继承Gallery的子类,重写onFling方法,返回false来实现手指拖动时图片只滚动一张的效果。
缺点:
使用方式1来实现,当你用手指拖动,就会发现图片滚动的太快了,不是一张一张的滚动的,没法使用继承Gallery的子类,重写onFling方法,返回false来实现手
使用方式2来实现 ,效果没那么好看,图片说换就换了,没缓冲,滚动速度没法控制。
‘伍’ android recyclerview 自动滚动什么情况
在工作中有时会遇到含有CheckBox 的ListView/Recyclerview时,发现当初始化CheckBox的状态后, 滚动ListView/Recyclerview,其中CheckBox 的选中状态不停的发生变化。最后发现原因 是ListView/Recyclerview滚动时自动调用 onCheckedChanged 导致的。
‘陆’ android怎么viewpager实现循环切换图片
Android中的ViewPager则实现了左右滑动的效果,ViewPager类提供了多界面切换的新效果。利用ViewPager实现图片循环滚动代码如下:
1、首先是布局文件,使用了一个ViewPager控件:
<spanstyle="padding:0px;margin:0px;font-size:14px;"><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/viewpager"
android:background="#33000000"
android:orientation="vertical"
android:padding="5dip">
<TextView
android:id="@+id/tv_image_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="第一个引导页面"
android:textColor="@android:color/white"
android:textSize="14sp"/>
<LinearLayout
android:id="@+id/ll_points"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:layout_gravity="center_horizontal"
android:orientation="horizontal">
</LinearLayout>
</LinearLayout>
</RelativeLayout></span>
2、接下来实现一个继承PagerAdapter的MyAdapter类,实现一个PagerAdapter,代码如下:
<spanstyle="padding:0px;margin:0px;font-size:14px;">packagecom.example.viewpagertest;
importjava.util.List;
importandroid.support.v4.view.PagerAdapter;
importandroid.view.View;
importandroid.view.ViewGroup;
importandroid.widget.ImageView;
{
privateList<ImageView>mImageViewList;
publicViewPagerAdapter(List<ImageView>imageViewList){
super();
this.mImageViewList=imageViewList;
}
/**
*该方法将返回所包含的Item总个数。为了实现一种循环滚动的效果,返回了基本整型的最大值,这样就会创建很多的Item,
*其实这并非是真正的无限循环。
*/
@Override
publicintgetCount(){
returnInteger.MAX_VALUE;
}
/**
*判断出去的view是否等于进来的view如果为true直接复用
*/
@Override
publicbooleanisViewFromObject(Viewarg0,Objectarg1){
returnarg0==arg1;
}
/**
*销毁预加载以外的view对象,会把需要销毁的对象的索引位置传进来,就是position,
*因为mImageViewList只有五条数据,而position将会取到很大的值,
*所以使用取余数的方法来获取每一条数据项。
*/
@Override
publicvoiddestroyItem(ViewGroupcontainer,intposition,Objectobject){
container.removeView(mImageViewList.get(position%mImageViewList.size()));
}
/**
*创建一个view,
*/
@Override
publicObjectinstantiateItem(ViewGroupcontainer,intposition){
container.addView(mImageViewList.get(position%mImageViewList.size()));
returnmImageViewList.get(position%mImageViewList.size());
}
}
</span>
3、最后是主界面部分的代码:
<spanstyle="padding:0px;margin:0px;font-size:14px;">packagecom.example.viewpagertest;
importjava.util.ArrayList;
importjava.util.List;
importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.os.Handler;
importandroid.os.Message;
importandroid.os.SystemClock;
importandroid.support.v4.view.ViewPager;
importandroid.support.v4.view.ViewPager.OnPageChangeListener;
importandroid.view.View;
importandroid.widget.ImageView;
importandroid.widget.LinearLayout;
importandroid.widget.LinearLayout.LayoutParams;
importandroid.widget.TextView;
{
privateList<ImageView>imageViewList;
privateTextViewtvDescription;
privateLinearLayoutllPoints;
privateString[]imageDescriptions;
=0;
privateViewPagermViewPager;
privatebooleanisLoop=true;
privateHandlerhandler=newHandler(){
@Override
publicvoidhandleMessage(Messagemsg){
super.handleMessage(msg);
mViewPager.setCurrentItem(mViewPager.getCurrentItem()+1);
}
};
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setView();
initView();
}
publicvoidsetView(){
setContentView(R.layout.activity_splash_viewpager);
//自动切换页面功能
newThread(newRunnable(){
@Override
publicvoidrun(){
while(isLoop){
SystemClock.sleep(2000);
handler.sendEmptyMessage(0);
}
}
}).start();
}
publicvoidinitView(){
mViewPager=(ViewPager)findViewById(R.id.viewpager);
tvDescription=(TextView)findViewById(R.id.tv_image_description);
llPoints=(LinearLayout)findViewById(R.id.ll_points);
prepareData();
ViewPagerAdapteradapter=newViewPagerAdapter(imageViewList);
mViewPager.setAdapter(adapter);
mViewPager.setOnPageChangeListener(this);
tvDescription.setText(imageDescriptions[previousSelectPosition]);
llPoints.getChildAt(previousSelectPosition).setEnabled(true);
/**
*2147483647/2=1073741820-1
*设置ViewPager的当前项为一个比较大的数,以便一开始就可以左右循环滑动
*/
intn=Integer.MAX_VALUE/2%imageViewList.size();
intitemPosition=Integer.MAX_VALUE/2-n;
mViewPager.setCurrentItem(itemPosition);
}
privatevoidprepareData(){
imageViewList=newArrayList<ImageView>();
int[]imageResIDs=getImageResIDs();
imageDescriptions=getImageDescription();
ImageViewiv;
Viewview;
for(inti=0;i<imageResIDs.length;i++){
iv=newImageView(this);
iv.setBackgroundResource(imageResIDs[i]);
imageViewList.add(iv);
//添加点view对象
view=newView(this);
view.setBackgroundDrawable(getResources().getDrawable(R.drawable.point_background));
LayoutParamslp=newLayoutParams(5,5);
lp.leftMargin=10;
view.setLayoutParams(lp);
view.setEnabled(false);
llPoints.addView(view);
}
}
privateint[]getImageResIDs(){
returnnewint[]{
R.drawable.bg1,
R.drawable.bg2,
R.drawable.bg3,
R.drawable.pic_01,
R.drawable.pic_02
};
}
privateString[]getImageDescription(){
returnnewString[]{
"第一个引导页面",
"第二个引导页面",
"第三个引导页面",
"第四个引导页面",
"第五个引导页面"
};
}
@Override
(intarg0){
}
@Override
publicvoidonPageScrolled(intarg0,floatarg1,intarg2){
}
@Override
publicvoidonPageSelected(intposition){
//改变图片的描述信息
tvDescription.setText(imageDescriptions[position%imageViewList.size()]);
//切换选中的点,把前一个点置为normal状态
llPoints.getChildAt(previousSelectPosition).setEnabled(false);
//把当前选中的position对应的点置为enabled状态
llPoints.getChildAt(position%imageViewList.size()).setEnabled(true);
previousSelectPosition=position%imageViewList.size();
}
@Override
protectedvoidonDestroy(){
super.onDestroy();
isLoop=false;
}
}
</span>
‘柒’ 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);
}
}
‘捌’ 如何让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
‘玖’ android如何利用horizon scrollview实现循环滚动
把要滚动的布局放在scrollview里面,
‘拾’ 安卓版按键精灵我想要同时滑动4个点然后无限循环,该怎么做
这个是要用多线程开实现的,就是可以开四个线程进行无限的循环操作,不过个人认为一般这样的操作用什么多线程啊,单线程就够了,因为CPU的计算能力提高很多,一秒种可以再四个点上滑动几十次所以这样的操作用单线程就够了,不用多线程。顺序滑动四个点就行了。