创建没有鼠标监听器的幻灯片

发布于 2024-12-10 08:26:29 字数 86 浏览 0 评论 0原文

我是 Android 新手,我想在没有任何监听器的情况下创建幻灯片,我的意思是我想打开我的应用程序并仅查看动画效果。我找不到示例或教程,有人可以帮助我吗?谢谢

I am new in android and I want to create slideshow without any listener, I mean I would like open my app and see just animation with effect. I can't find examples or tutorials, anyone could help me? Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

撑一把青伞 2024-12-17 08:26:29

如果您想在没有用户交互的情况下自动执行任何操作,则必须使用后台线程。在 Android 中,您无法从后台线程调用修改 UI 的方法。当您计划定期更新 UI 时,最好使用 AsynchTash

private class SwitchImagesTask extends AsyncTask<Integer, Integer, Intehger> {
     protected Long doInBackground(Integer... itemCount) {
         for (int i = 0; i < itemCount[0]; i++) {
               try{Thread.wait(1000);}catch(Exception e) {return -1;}
               publishProgress(i);
         }
         return 1;
     }

     protected void onProgressUpdate(Integer... progress) {
          // Display your image here
     }

     protected void onPostExecute(Integer result) {
          // Say goodby to the user
     }
 }

如果幻灯片放映意味着一张又一张图像,那么最简单的方法是将 ImageView 添加到布局中,并且 更改其内容。

If you want to do anything automatically without user interaction, than you have to use a backgroud thread. In Android you cannot call methods modifying the UI fron a background thread. As you plan on periodically updating the UI, you will be best off with AsynchTash.

private class SwitchImagesTask extends AsyncTask<Integer, Integer, Intehger> {
     protected Long doInBackground(Integer... itemCount) {
         for (int i = 0; i < itemCount[0]; i++) {
               try{Thread.wait(1000);}catch(Exception e) {return -1;}
               publishProgress(i);
         }
         return 1;
     }

     protected void onProgressUpdate(Integer... progress) {
          // Display your image here
     }

     protected void onPostExecute(Integer result) {
          // Say goodby to the user
     }
 }

If slide show means one image after another, than the easiest way to do this will be to add an ImageView to the layout, and change it's content.

一百个冬季 2024-12-17 08:26:29

如果您调用活动,您可以在扩展线程的内部类中使用布局充气器。

public class SlideshowActivity extends Activity {

private static final int[] mSlides = new int[]{R.layout.layout_a , R.layout.layout_b , R.layout.layout_c};  

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    new StartSlideShow().start();
}

class StartSlideShow extends Thread
{ 
    @Override
    public void run() {
        LayoutInflater inflator = SlideshowActivity.this.getLayoutInflater();
        for(int inx = 0 ; inx < mSlides.length ; inx++)
        {               
            try {
                sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            inflator.inflate(mSlides[inx], null);
        }
    }
}

}

if you call a activity, you can use layout inflator in inner class which extends thread.

public class SlideshowActivity extends Activity {

private static final int[] mSlides = new int[]{R.layout.layout_a , R.layout.layout_b , R.layout.layout_c};  

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    new StartSlideShow().start();
}

class StartSlideShow extends Thread
{ 
    @Override
    public void run() {
        LayoutInflater inflator = SlideshowActivity.this.getLayoutInflater();
        for(int inx = 0 ; inx < mSlides.length ; inx++)
        {               
            try {
                sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            inflator.inflate(mSlides[inx], null);
        }
    }
}

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文