① android 线程的循环
设置标记变量,while(isValid){} 如果想退出的时候,将isValid置为false
② Android开发中 循环命令 怎么 循环一次先后执行两条命令
1. 下载sdk时下载了docs/reference文档,文档是html形式的,因为里面带有google的相关网址,浏览器打开时会去访问这些被墙的网址,所以显示巨慢。
2. 解决办法就是遍历子目录删除google相关网址,由于是android开发,就用java实现吧.
③ android 如何正确循环删除list中的数据
当我们使用for循环删除列表中的数据的时候,会存在问题,因为ArrayList的父类AbstractList里有个modCount的字段记录着List的总数,for循环的时候如果增加或者删除了元素,(修改不会影响),此字段会变化,那么在下次for循环的时候检查到跟之前的长度不同,此时会报异常。
解决方法如下:
Iterator it=lists.iterator();
while(it.hasNext){
it.next();
if(true){
it.remove();
}
}
④ android studio中怎么快速生成for循环语句
需要自定义代码块,自定义代码块步骤:
点击“Settings——>Editor——>Live Templates”右边的“+”号
可以选择Live Template或Template Group,Live Template默认当前对应添加的模块
Template Group为添加的模块名称分组,比如:CustomGroup,然后选中该分组后添加Live Template
在Template text中输入for循环结构体,Abbreviation设置快捷输入for:
for(inti=0;i<a.length;i++){};
⑤ 有Android的可以循环播放的手机视频软件吗
MX Player pro。
⑥ Android开发音乐播放器,如何实现单曲循环,顺序播放,随机播放,全部循环功能,高分求助
MediaPlayer 对象调用setLooping(true);是循环播放。
顺序播放,随机播放,全部循环功能 这些就是自己写方法实现就好了,
顺序播放就是当一首歌播放完后,在播放列表中找到它下一首歌的ID,直到全部完成。
随机播放就是当一首歌播放完后,在播放列表中随机抽取一首歌的ID(排除已经播放),直到全部完成。
全部循环就是顺序播放全部歌曲,到最后一首之后从第一首播放。
⑦ 怎么能让安卓手机视频无限循环播放
现在华为的手机已经可以实现这一功能了,其它手机我不清楚能不能实现:
点开(图库),点开(视频),点开某一段视频,点播放,点右上角的三个小点,出来一个页面,点上面的(播放设置)的(单片循环),然后就可以看到该视频不断重复播放了。如果有多个视频想一起播放,也可以点(播放设置)的(全部循环),就全部播放,循环不停。
⑧ android循环取ListView中的数据
只需要循环一下,判断即可。
示例代码:
1.遍历整个list集合
for(int i=0; i<list.size(); i++){
}
2.在for循环中增加判断代码
if(list.get(i).equals("指定")){}
3.得到每一个item进行判断即可。
⑨ 安卓系统桌面循环滚动桌面设置的
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就可以了。
⑩ android两个animation无限循环怎么做
据我所知,想直接给AnimationSet设置重复,是不行的。不过你可以这样来:
final int transDuration = 2000;
final int alphaDuration = 1000;
AnimationSet set = new AnimationSet(false);
set.setRepeatMode(Animation.RESTART);
TranslateAnimation translateAnimation = new TranslateAnimation(0, 0, 0, 300);
translateAnimation.setInterpolator(new Interpolator() {
@Override
public float getInterpolation(float arg0) {
float ret = arg0 / (1.0f * transDuration / (transDuration + alphaDuration));
return ret < 1 ? ret : 1;
}
});
translateAnimation.setRepeatCount(Animation.INFINITE);
translateAnimation.setDuration(transDuration + alphaDuration);
AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
alphaAnimation.setRepeatCount(Animation.INFINITE);
alphaAnimation.setDuration(alphaDuration);
alphaAnimation.setStartOffset(transDuration);
set.addAnimation(translateAnimation);
set.addAnimation(alphaAnimation);
view.startAnimation(set);
或者像其他所说的,通过在一个动画结束后开始另外一个动画的方式。