回答

1

你可以用ViewPager做到这一点。最好的旋转木马就像使用recylerview一样。但你需要自定义的LayoutManager的第一个速度减慢像旋转木马

创建Recyclerview

CustomLayoutManager layoutManager = new CustomLayoutManager(getActivity()); 
layoutManager.setSpeed(1500f); 
layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL); 

然后创建CustomLayoutManager改变recylcerview滚动的速度

public class CustomLayoutManager extends LinearLayoutManager { 
    private float MILLISECONDS_PER_INCH = 1100f; 
    private Context mContext; 

    public CustomLayoutManager(Context context) { 
     super(context); 
     mContext = context; 
    } 

    @Override 
    public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, final int position) { 

     LinearSmoothScroller smoothScroller = new LinearSmoothScroller(mContext) { 
        @Override 
        public PointF computeScrollVectorForPosition(int targetPosition) { 
         return CustomLayoutManager.this.computeScrollVectorForPosition(targetPosition); 
        } 

        @Override 
        protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) { 
         return MILLISECONDS_PER_INCH/displayMetrics.densityDpi; 
        } 
       }; 

     smoothScroller.setTargetPosition(position); 
     startSmoothScroll(smoothScroller); 
    } 

    public void setSpeed(float speed){ 
     this.MILLISECONDS_PER_INCH = speed; 
    } 
} 

然后在您的活动或片段,创建Runnable

Runnable runNews = new Runnable() { 
     @Override 
     public void run() { 
      try { 
       top_new_rview.smoothScrollToPosition(++counter); 
       handler.postDelayed(this, replay); 
      } catch (Exception e) { 
       handler.removeCallbacks(runNews); 
       onError(getActivity(), e); 
      } 
     } 
    };