• <legend id='45SYR'><style id='45SYR'><dir id='45SYR'><q id='45SYR'></q></dir></style></legend>

    1. <small id='45SYR'></small><noframes id='45SYR'>

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

        如何自动滑动android View Pager

        时间:2023-10-04
      1. <i id='myRMi'><tr id='myRMi'><dt id='myRMi'><q id='myRMi'><span id='myRMi'><b id='myRMi'><form id='myRMi'><ins id='myRMi'></ins><ul id='myRMi'></ul><sub id='myRMi'></sub></form><legend id='myRMi'></legend><bdo id='myRMi'><pre id='myRMi'><center id='myRMi'></center></pre></bdo></b><th id='myRMi'></th></span></q></dt></tr></i><div id='myRMi'><tfoot id='myRMi'></tfoot><dl id='myRMi'><fieldset id='myRMi'></fieldset></dl></div>
        <legend id='myRMi'><style id='myRMi'><dir id='myRMi'><q id='myRMi'></q></dir></style></legend>
          <tbody id='myRMi'></tbody>

            <bdo id='myRMi'></bdo><ul id='myRMi'></ul>

          • <tfoot id='myRMi'></tfoot>
          • <small id='myRMi'></small><noframes id='myRMi'>

                  本文介绍了如何自动滑动android View Pager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  可以将 View Pager 设置为自动滑动或自动翻页.我将我的 viewpager 设置为使用如下所示的适配器,它工作正常:-

                  Can a View Pager be made to auto slide or autopage. I have my viewpager set up to use the adapter like the below and it works fine:-

                  @Override
                  public void onCreate(Bundle savedInstanceState) {
                  super.onCreate(savedInstanceState);
                  
                  setContentView(R.layout.gridslide);
                  ImagePagerAdapter mAdapter = new ImagePagerAdapter(
                          getSupportFragmentManager(),4);
                  ViewPager mPager = (ViewPager) findViewById(R.id.pager);
                  mPager.setAdapter(mAdapter);
                  }
                  

                  适配器如下:-

                  public static class ImagePagerAdapter extends FragmentStatePagerAdapter {
                  private final int mSize;
                  
                  public ImagePagerAdapter(FragmentManager fm, int size) {
                      super(fm);
                      mSize = size;
                  }
                  
                  @Override
                  public int getCount() {
                      return mSize;
                  }
                  @Override
                  public Fragment getItem(int position) {
                      Log.v(TAG,"position="+position);
                      return TheFragment.newInstance(position);
                  }}
                  

                  但是我想知道如何让这些片段在 viewpager 中自动滑动.

                  However I would want to know how to make these fragments autoslide in a viewpager.

                  推荐答案

                  在 setCurrentItem(int item, boolean smoothScroll) 中设置 smoothScroll = true 并不总是有平滑滚动的效果.假设如果您的 viewpager 中的页面少于 5 个,您几乎不会注意到平滑滚动.

                  Setting smoothScroll = true in setCurrentItem(int item, boolean smoothScroll) does not always have the smooth scroll effect. Suppose if you have less than 5 pages in you viewpager, you will hardly notice the smooth scroll.

                  在这种情况下,最困难的方法是把它放在一个 for 循环中

                  In this scenario, the hard way to do it is to put it in a for loop

                  //This will scroll page-by-page so that you can view scroll happening
                  for (int i = 0; i < mAdapter.getCount()-1; i++)
                      mPager.setCurrentItem(i, true);
                  

                  如果有人需要更慢的滚动,他们可以像这样使用 postDelayed()...

                  If some one needs more slower scroll, they can use postDelayed() like this...

                  static int i=0;
                  private final Handler handler = new Handler();
                  somefunction()
                  {
                      handle.post(ViewPagerVisibleScroll);
                  }
                  
                      Runnable ViewPagerVisibleScroll= new Runnable() {
                                  @Override
                                  public void run() {
                                      if(i <= mAdapter.getCount()-1)
                                      {
                                          mPager.setCurrentItem(i, true);
                                          handle.postDelayed(TopChartAnimation, 100);
                                          i++;
                                      }
                                  }
                              };
                  

                  总是不推荐休眠:如果有人需要更慢的滚动,他们可能会在这个 for 循环中使用休眠...

                  Sleep is always NOT recommended : If some one needs more slower scroll, they may use a sleep in this for loop...

                  @Override
                  public void onClick(View v) {
                  Runnable runnable = new Runnable() {
                                  @Override
                                  public void run() {
                                      for (int i = 0; i < mAdapter.getCount()-1; i++) {
                                          final int value = i;
                                          try {
                                              Thread.sleep(50);
                                          } catch (InterruptedException e) {
                                              e.printStackTrace();
                                          }
                                          handler.post(new Runnable() {
                                              @Override
                                              public void run() {
                                                  mPager.setCurrentItem(value, true);
                                              }
                                          });
                                      }
                                  }
                              };
                              new Thread(runnable).start();
                  
                          }
                  

                  这篇关于如何自动滑动android View Pager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:DialogFragment 中的 ViewPager - IllegalStateException:片段没有视图 下一篇:viewpager 页面中 mapview 的手势问题

                  相关文章

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

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

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