<legend id='CTB54'><style id='CTB54'><dir id='CTB54'><q id='CTB54'></q></dir></style></legend>
    <bdo id='CTB54'></bdo><ul id='CTB54'></ul>
<i id='CTB54'><tr id='CTB54'><dt id='CTB54'><q id='CTB54'><span id='CTB54'><b id='CTB54'><form id='CTB54'><ins id='CTB54'></ins><ul id='CTB54'></ul><sub id='CTB54'></sub></form><legend id='CTB54'></legend><bdo id='CTB54'><pre id='CTB54'><center id='CTB54'></center></pre></bdo></b><th id='CTB54'></th></span></q></dt></tr></i><div id='CTB54'><tfoot id='CTB54'></tfoot><dl id='CTB54'><fieldset id='CTB54'></fieldset></dl></div>

    1. <tfoot id='CTB54'></tfoot>

      1. <small id='CTB54'></small><noframes id='CTB54'>

        android viewpager中的幻灯片?

        时间:2023-10-04

        <small id='KRTpp'></small><noframes id='KRTpp'>

          <legend id='KRTpp'><style id='KRTpp'><dir id='KRTpp'><q id='KRTpp'></q></dir></style></legend>
            <bdo id='KRTpp'></bdo><ul id='KRTpp'></ul>

            <i id='KRTpp'><tr id='KRTpp'><dt id='KRTpp'><q id='KRTpp'><span id='KRTpp'><b id='KRTpp'><form id='KRTpp'><ins id='KRTpp'></ins><ul id='KRTpp'></ul><sub id='KRTpp'></sub></form><legend id='KRTpp'></legend><bdo id='KRTpp'><pre id='KRTpp'><center id='KRTpp'></center></pre></bdo></b><th id='KRTpp'></th></span></q></dt></tr></i><div id='KRTpp'><tfoot id='KRTpp'></tfoot><dl id='KRTpp'><fieldset id='KRTpp'></fieldset></dl></div>
                <tbody id='KRTpp'></tbody>
            • <tfoot id='KRTpp'></tfoot>

                • 本文介绍了android viewpager中的幻灯片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在使用 android viewpager 幻灯片时遇到问题.我想在最短时间后显示 viewpager 布局.这是我的代码示例.我的主要课程:

                  I have problem with android viewpager slideshow. I want to show the viewpager layout after a minimum time period. Here is my code sample. My main class:

                  public class MainActivity extends Activity {
                      private ViewPager mViewPager;
                      private SwipeAdapter adapter;
                  
                      @Override
                      protected void onCreate(Bundle savedInstanceState) {
                          super.onCreate(savedInstanceState);
                          setContentView(R.layout.activity_main);
                          mViewPager = (ViewPager) findViewById(R.id.pager);
                          // set the adapter
                          adapter = new SwipeAdapter(MainActivity.this);
                          mViewPager.setAdapter(adapter);
                  
                          mViewPager.setOnPageChangeListener(new OnPageChangeListener() {
                  
                              @Override
                              public void onPageSelected(int position) {
                              }
                  
                              @Override
                              public void onPageScrolled(int arg0, float arg1, int arg2) {
                              }
                              @Override
                              public void onPageScrollStateChanged(int arg0) {
                              }
                          });
                      }
                  
                  }
                  

                  我的适配器类:

                  public class SwipeAdapter extends PagerAdapter {
                  
                      private LayoutInflater mInflater;
                      private static int[] mLayouts = { R.layout.view_layout1,
                              R.layout.view_layout2, R.layout.view_layout3, R.layout.view_layout4 };
                  
                      SwipeAdapter(Context context) {
                          mInflater = LayoutInflater.from(context);
                      }
                  
                      @Override
                      public void destroyItem(ViewGroup container, int position, Object object) {
                          container.removeView((View) object);
                      }
                  
                      @Override
                      public Object instantiateItem(ViewGroup container, int position) {
                          ViewGroup pageView = (ViewGroup) mInflater.inflate(mLayouts[position],
                                  container, false);
                          container.addView(pageView);
                          getItemPosition(pageView);
                          return pageView;
                      }
                  
                      @Override
                      public int getCount() {
                          return mLayouts.length;
                      }
                      @Override
                      public boolean isViewFromObject(View view, Object obj) {
                          return view == obj;
                      }
                  }
                  

                  假设我想让 viewpager 布局在 10 秒后自动滑动.怎么可能.

                  suppose that I want to make the viewpager layout auto sliding after 10 seconds. How can it possible.

                  推荐答案

                  使用Handler让它自动滑动.这是一些代码

                  Use Handler to make it auto slide. Here is some code

                  private Handler handler = new Handler();
                  private Runnable runnable = new Runnable() {
                      public void run() {
                              if( position >= 4){
                                  position = 0;
                              }else{
                                  position = position+1;
                              }
                              toBarPager.setCurrentItem(position, true);
                              handler.postDelayed(runnable, 10000);
                      }
                  };
                  

                  别忘了移除回调onPause()

                  @Override
                  public void onPause() {
                      super.onPause();
                      if (handler!= null) {
                          handler.removeCallbacks(runnable);
                      }
                  }
                  

                  另外,别忘了重新运行 onResume()

                  Also, don't forget to rerun onResume()

                  @Override
                  public void onResume() {
                      super.onResume();  // Always call the superclass method first
                      handler.postDelayed(runnable, 10000);
                  }
                  

                  这篇关于android viewpager中的幻灯片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:带有标签和 Viewpager 的 Android 片段 下一篇:ViewPager + PagerAdapter 在前两项后显示空白页

                  相关文章

                • <legend id='us1kQ'><style id='us1kQ'><dir id='us1kQ'><q id='us1kQ'></q></dir></style></legend>
                    <bdo id='us1kQ'></bdo><ul id='us1kQ'></ul>

                      <i id='us1kQ'><tr id='us1kQ'><dt id='us1kQ'><q id='us1kQ'><span id='us1kQ'><b id='us1kQ'><form id='us1kQ'><ins id='us1kQ'></ins><ul id='us1kQ'></ul><sub id='us1kQ'></sub></form><legend id='us1kQ'></legend><bdo id='us1kQ'><pre id='us1kQ'><center id='us1kQ'></center></pre></bdo></b><th id='us1kQ'></th></span></q></dt></tr></i><div id='us1kQ'><tfoot id='us1kQ'></tfoot><dl id='us1kQ'><fieldset id='us1kQ'></fieldset></dl></div>
                    1. <tfoot id='us1kQ'></tfoot>

                      <small id='us1kQ'></small><noframes id='us1kQ'>