简体   繁体   English

仅第一次下一页的ViewPager部分视图

[英]ViewPager partial view of next page first time only

I want to tell the user that s/he can swipe to change page. 我想告诉用户他/她可以滑动以更改页面。 So I want to show a partial view of the next page. 因此,我想显示下一页的局部视图。 But that only the very first time. 但这只是第一次。 So I figure I would use the code 所以我想我会使用代码

boolean mFirstTime = true;
@Override
public float getPageWidth(int position) {
  if (position == 0 && mFirstTime) {
    mFirstTime = false;
    return 0.9f;
  }
  return 1f;
}

But my mFirstTime has no apparent effect. 但是我的mFirstTime没有明显的作用。 Does anyone know a way to achieve my end? 有谁知道实现我目标的方法? I image I could use a listener of sort, but I don't know what would go inside the listener. 我想象我可以使用某种侦听器,但是我不知道侦听器内部会发生什么。

Update 更新资料

Alternatively I tried the snippet below to no avail. 另外,我尝试了下面的代码片段也无济于事。

myPager.beginFakeDrag();
myPager.fakeDragBy(Utils.dpToPx(this, 50));
myPager.endFakeDrag();

where the subroutine is 子程序在哪里

public static int dpToPx(Context context, int dp) {
  return (int) Math.ceil(dp * context.getResources().getDisplayMetrics().density);
}

You need to do the following for it to work. 您需要执行以下操作才能使其工作。

  1. if you're not extending FragmentStatePagerAdapter -> you need to extand that instead of just PagerAdapter 如果您不扩展FragmentStatePagerAdapter->您需要扩展它,而不仅仅是PagerAdapter
  2. You need to override the method 您需要重写方法

     @Override public int getItemPosition(Object obj){ return POSITION_NONE; //will cause data reload } 

and when you're ready to display the page at full size, call adapter.notifyDataSetChanged() 当您准备好以全尺寸显示页面时,请调用adapter.notifyDataSetChanged()

which will cause the getPageWidth() to be called for each page again, making it grow 这将导致再次为每个页面调用getPageWidth() ,使其增长

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM