我希望在我的安卓应用程序中使用html中的跑马灯功能。我不知道在安卓中该如何称呼它。
例如,我有四到五个图像,它们需要自动从左到右或从右到左滚动。
1 注意-我不是在问关于水平滚动视图的问题。
如何实现这个功能?
我希望在我的安卓应用程序中使用html中的跑马灯功能。我不知道在安卓中该如何称呼它。
例如,我有四到五个图像,它们需要自动从左到右或从右到左滚动。
1 注意-我不是在问关于水平滚动视图的问题。
如何实现这个功能?
public class AutoSlider extends Activity {
public int currentimageindex=0;
Timer timer;
TimerTask task;
ImageView slidingimage;
int[] IMAGE_IDS = {R.drawable.image1, R.drawable.image2, R.drawable.image3,
R.drawable.image4};
@Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Handler mHandler = new Handler();
// Create runnable for posting
final Runnable mUpdateResults = new Runnable() {
public void run() {
AnimateandSlideShow();
}
};
int delay = 1000; // delay for 1 sec.
int period = 8000; // repeat every 4 sec.
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
mHandler.post(mUpdateResults);
}
}, delay, period);
}
public void onClick(View v) {
finish();
android.os.Process.killProcess(android.os.Process.myPid());
}
private void AnimateandSlideShow() {
slidingimage = (ImageView)findViewById(R.id.ImageView_id);
slidingimage.setImageResource(IMAGE_IDS[currentimageindex%IMAGE_IDS.length]);
currentimageindex++;
}
}
在你的XML中,只需要布局和ImageView以及它的宽度、高度和位置。
视图页面的官方定义:
Layout manager that allows the user to flip left and right through pages of data. You supply an implementation of a PagerAdapter to generate the pages that the view shows
http://wptrafficanalyzer.in/blog/image-slideshow-using-viewflipper-in-android/(使用视图翻转器)