Android 查看寻呼机未顺利滑动

Android 查看寻呼机未顺利滑动,android,Android,这是我的代码,请检查并告诉我问题出在哪里。fragment在第二次刷卡时大多不顺畅。我使用FragmentPagerAdapter和OverridegetItemPosition()方法进行了检查,但找不到解决方案 //View Pager Adapter public class MyBookingPagerAdapter extends FragmentStatePagerAdapter{ private ArrayList<Booking> bookingLi

这是我的代码,请检查并告诉我问题出在哪里。
fragment
在第二次刷卡时大多不顺畅。我使用
FragmentPagerAdapter
和Override
getItemPosition()
方法进行了检查,但找不到解决方案

    //View Pager Adapter

public class MyBookingPagerAdapter extends FragmentStatePagerAdapter{
    private ArrayList<Booking> bookingList;
    public MyBookingPagerAdapter(FragmentManager fm,ArrayList<Booking> bookingList) {
        super(fm);
        this.bookingList=bookingList;
    }

    @Override
    public Fragment getItem(int position) {
        return MyBookingFragment.newInstance(bookingList.get(position));
    }

    @Override
    public int getCount() {
        return bookingList.size();
    }

    @Override
    public int getItemPosition(Object object) {
        return POSITION_NONE;
    }
}

//View Pager Fragment

public class MyBookingFragment extends BaseFragment {
    private Booking booking;
    private RelativeLayout containerTopView;
    private TextView txtTitle,txtAddress,txtDay,txtMonth,txtShowDayName,txtShowDate,txtLastEntyTime,txtFemalesprice,txtCouplePrice,txtMalesPrice,txtTotalAmount;
    private ImageView imgTopView;
    private LinearLayout dotsContainer;

    public static MyBookingFragment newInstance(Booking booking){
        MyBookingFragment fragmentMyBooking= new MyBookingFragment();
        Bundle args=new Bundle();
        args.putSerializable("booking",booking);
        fragmentMyBooking.setArguments(args);
        return fragmentMyBooking;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_my_booking_appbar,container,false);
        //      init Layout view (find View By Id from the xml)
        initViews(view);

        //      Set booking values of views
        if(booking!=null)
            setValues(booking);
        return view;
    }



    private void setValues(Booking booking) {
        txtTitle.setText(booking.getEventName());
        txtAddress.setText(booking.getAddress());
        txtShowDayName.setText(booking.getDayName());
        txtShowDate.setText(booking.getBookingDate());
        txtLastEntyTime.setText(booking.getBookingTime());
        txtFemalesprice.setText(booking.getFemale()+" x +getString(R.string.Rs)+booking.getLaydiesPrice());
        txtMalesPrice.setText(booking.getMale()+" x "+getString(R.string.Rs)+booking.getStageEntryPrice());
        txtCouplePrice.setText(booking.getCouple()+" x "+getString(R.string.Rs)+booking.getCouplePrice());
        txtTotalAmount.setText(booking.getTotalPrice());
        try{
      ImageLoader.getInstance().displayImage(booking.getImgTopView(),imgTopView);
        }catch (Exception e){
            Utils.print("MyBookingFragment ImageLoader",e.toString());
        }
    }

    private void initViews(View view) {
        txtShowDayName= (TextView) view.findViewById(R.id.txtMyBookingShowDay);
        txtShowDate= (TextView) view.findViewById(R.id.txtMyBookingShowDate);
        txtLastEntyTime= (TextView) view.findViewById(R.id.txtMyBookingLastEntryTime);
        txtFemalesprice= (TextView) view.findViewById(R.id.txtMyBookingFemalePrice);
        txtMalesPrice= (TextView) view.findViewById(R.id.txtMyBookingMalesPrice);
        txtCouplePrice= (TextView) view.findViewById(R.id.txtMyBookingCouplePrice);
        txtTotalAmount= (TextView) view.findViewById(R.id.txtMyBookingTotal);
        txtAddress= (TextView) view.findViewById(R.id.txtMyBookingAddress);
        txtTitle= (TextView) view.findViewById(R.id.txtMyBookingTitle);
        imgTopView=(ImageView) view.findViewById(R.id.imgTopView);
        containerTopView= (RelativeLayout) view.findViewById(R.id.containerTopView);
        booking= (Booking) getArguments().getSerializable("booking");
    }

}

//Setting View Pager Adapter

                    adapter=new MyBookingPagerAdapter(getSupportFragmentManager(),bookingArrayList);
                    pager.setAdapter(adapter);
                    pager.setOffscreenPageLimit(3);



                    //      showing no data msg view
                    if(adapter.getCount()<=0)
                        findViewById(R.id.frameNoData).setVisibility(View.VISIBLE);
                    else{
                        setIndicators(bookingArrayList.size());
                        pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                            @Override
                            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}
                            @Override
                            public void onPageSelected(int position) {
                                if(indicators!=null)
                                    indicators[position].setChecked(true);
                            }
                            @Override
                            public void onPageScrollStateChanged(int state) { } });
//查看寻呼机适配器
公共类MyBookingPagerAdapter扩展了FragmentStatePagerAdapter{
私人ArrayList bookingList;
公共MyBookingPagerAdapter(FragmentManager格式,ArrayList bookingList){
超级(fm);
this.bookingList=bookingList;
}
@凌驾
公共片段getItem(int位置){
返回MyBookingFragment.newInstance(bookingList.get(position));
}
@凌驾
public int getCount(){
return bookingList.size();
}
@凌驾
public int getItemPosition(对象){
返回位置\无;
}
}
//查看寻呼机片段
公共类MyBookingFragment扩展了BaseFragment{
私人订票;
私有RelativeLayout containerTopView;
私有文本视图txtTitle、txtAddress、txtDay、txtMonth、txtShowDayName、txtShowDate、txtLastEntyTime、txtFemalesprice、txtCouplePrice、txtMalesPrice、txtTotalAmount;
私有图像视图imgTopView;
私人线路布局点容器;
公共静态MyBookingFragment新实例(预订){
MyBookingFragment fragmentMyBooking=新建MyBookingFragment();
Bundle args=新Bundle();
args.putSerializable(“预订”,预订);
fragmentMyBooking.setArguments(args);
返回我的预订;
}
@可空
@凌驾
创建视图时的公共视图(LayoutFlater充气机、@Nullable ViewGroup容器、@Nullable Bundle savedInstanceState){
视图=充气机。充气(R.layout.fragment\u my\u booking\u appbar,container,false);
//初始化布局视图(从xml中按Id查找视图)
初始视图(视图);
//设置视图的预订值
如果(预订!=null)
设定价值(预订);
返回视图;
}
私人无效设置值(预订){
setText(booking.getEventName());
setxt(booking.getAddress());
txtShowDayName.setText(booking.getDayName());
txtShowDate.setText(booking.getBookingDate());
setText(booking.getBookingTime());
txtFemalesprice.setText(booking.getFemale()+“x+getString(R.string.Rs)+booking.getLaydiesPrice());
setText(booking.getMale()+“x”+getString(R.string.Rs)+booking.getStageEntryPrice());
setText(booking.getCouple()+“x”+getString(R.string.Rs)+booking.getCouplePrice());
txtotalAmount.setText(booking.getTotalPrice());
试一试{
ImageLoader.getInstance().displayImage(booking.getImgTopView(),imgTopView);
}捕获(例外e){
print(“MyBookingFragment ImageLoader”,例如toString());
}
}
私有void initViews(视图){
txtShowDayName=(TextView)view.findViewById(R.id.txtMyBookingShowDay);
txtShowDate=(TextView)view.findViewById(R.id.txtMyBookingShowDate);
txtLastEntyTime=(TextView)view.findViewById(R.id.txtMyBookingLastEntryTime);
txtFemalePrice=(TextView)view.findViewById(R.id.txtMyBookingFemalePrice);
txtmelsprice=(TextView)view.findViewById(R.id.txtMyBookingMalesPrice);
txtCouplePrice=(TextView)view.findViewById(R.id.txtMyBookingCouplePrice);
txtTotalAmount=(TextView)view.findViewById(R.id.txtMyBookingTotal);
txtAddress=(TextView)view.findViewById(R.id.txtMyBookingAddress);
txtTitle=(TextView)view.findViewById(R.id.txtMyBookingTitle);
imgTopView=(ImageView)view.findviewbyd(R.id.imgTopView);
containerTopView=(RelativeLayout)view.findViewById(R.id.containerTopView);
booking=(booking)getArguments().getSerializable(“booking”);
}
}
//设置视图寻呼机适配器
适配器=新MyBookingPagerAdapter(getSupportFragmentManager(),bookingArrayList);
寻呼机设置适配器(适配器);
pager.setOffscreenPageLimit(3);
//显示无数据msg视图

如果(adapter.getCount()自定义
ViewPager
类:

public class ViewPagerCustomDuration extends ViewPager {

public ViewPagerCustomDuration(Context context) {
    super(context);
    scrollInitViewPager();
}

public ViewPagerCustomDuration(Context context, AttributeSet attrs) {
    super(context, attrs);
    scrollInitViewPager();
}

private ScrollerCustomDuration mScroller = null;

private void scrollInitViewPager() {
    try {
        Field scroller = ViewPager.class.getDeclaredField("mScroller");
        scroller.setAccessible(true);
        Field interpolator = ViewPager.class.getDeclaredField("sInterpolator");
        interpolator.setAccessible(true);
        mScroller = new ScrollerCustomDuration(getContext(), (Interpolator) interpolator.get(null));
        scroller.set(this, mScroller);
    } catch (Exception e) {
    }
}
}
ScrollerCustomDuration.Java

public class ScrollerCustomDuration extends Scroller {

private double mScrollFactor = 1;

public ScrollerCustomDuration(Context context) {
    super(context);
}

public ScrollerCustomDuration(Context context, Interpolator interpolator) {
    super(context, interpolator);
}

@SuppressLint("NewApi")
public ScrollerCustomDuration(Context context, Interpolator interpolator, boolean flywheel) {
    super(context, interpolator, flywheel);
}

/**
 * Set the factor by which the duration will change
 */
public void setScrollDurationFactor(double scrollFactor) {
    mScrollFactor = scrollFactor;
}

@Override
public void startScroll(int startX, int startY, int dx, int dy, int duration) {
    super.startScroll(startX, startY, dx, dy, (int) (duration * mScrollFactor));
}

}

现在,在xml文件中,使用
ViewPagerCustomDuration
而不是默认的
ViewPager

每次在
onCreateView()
中创建视图。请将视图保存在全局视图变量中并使用该变量

View  view;
in onCreateView()
// 
if(view=null){
view=infla ter.inflate(R.layout.fragment_my_booking_appbar,container,false);
}

请检查您是否每次都在创建新片段,请给您的片段添加一个标记,并通过标记从FragmentManager获取片段。

可能是内存问题,请尝试另一个具有良好规格的设备,并解决它。ScrollerCustomDuration呢?是否有自定义类?是的,我忘了提及。请检查我的编辑。有关更多信息,请参阅通过滚动,您可以增加scrollfactor变量。没有任何改进(主要是在第二次或第三次滑动时,它跳过片段滑动,否则工作正常),那么您应该在您的代码中设置
mpager.setOffscreenPageLimit(2);
是的,我已经与mpager.setOffscreenPageLimit(2)和mpager.setOffscreenPageLimit(3)进行了检查;但没有解决。