2017-06-06 64 views
-1

我想用有限的可视项目的简单无尽的滚动横向滚动型像下面的图片: http://i.stack.imgur.com/uDqkn.jpg无尽滚动水平滚动型与有限的可视项目

这样的形象在4次可见的时间,并显示在最后一个项目第一件物品的左侧,就像任何旋转木马作品一样。

目前我使用simpel Horizo​​ntalScrollView:

<HorizontalScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:overScrollMode="never" 
    android:requiresFadingEdge="none" 
    android:scrollbars="none"> 

    <LinearLayout 
     android:id="@+id/itv_tabs_container" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

<!--Some Views--> 

     </LinearLayout> 
</LinearLayout> 

,但我需要是圆形..喜欢我可以移动到两个方向,没有任何限制

任何建议或链接会有所帮助。

感谢

+0

它看起来像你需要水平的'RecyclerView'具有无限的('Integer.MAX_VALUE')计数项目,从中间位置开始('Integer.MAX_VALUE/2'),并且'getItem'返回items.get(position %items.size())'。显示你当前的工作,适配器和列表初始化 – snachmsm

+0

目前我已经添加了一个简单的Horizntal scrollView,但我需要这是圆形的..就像我可以将它移动到两个方向没有任何限制。 – NehaK

+0

我用过android.widget.Horizo​​ntalScrollView – NehaK

回答

1

关注Creating Lists and Cards有以下变化:

  1. 在XML RecyclerView元素与价值horizontal

    <!-- A RecyclerView with some commonly used attributes --> 
    <android.support.v7.widget.RecyclerView 
        android:id="@+id/my_recycler_view" 
        android:scrollbars="vertical" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:orientation="horizontal" /> // <-- this is changed 
    
  2. 添加android:orientation属性设置RecyclerView滚动到中间位置后:

    // specify an adapter (see also next example) 
    mAdapter = new MyAdapter(myDataset); 
    mRecyclerView.setAdapter(mAdapter); 
    mRecyclerView.scrollToPosition(Integer.MAX_VALUE/2); 
    
  3. 更新onBindViewHolder()返回正确ViewHolder在案值超过上限:

    // Replace the contents of a view (invoked by the layout manager) 
    @Override 
    public void onBindViewHolder(ViewHolder holder, int position) { 
        // - get element from your dataset at this position 
        // - replace the contents of the view with that element 
        holder.mTextView.setText(mDataset[position % mDataset.length]); // <-- this is changed 
    } 
    
  4. 最后,从getItemCount()

    // Return the size of your dataset (invoked by the layout manager) 
    @Override 
    public int getItemCount() { 
        return Integer.MAX_VALUE; 
    } 
    

限制返回Integer.MAX_VALUE 我假设用户不会滚动视图Integer.MAX_VALUE/2次否则他们会达到结束。

希望这会有所帮助。

+0

谢谢,我会试试这个。 – NehaK

+0

除了回收站视图还有其他方法吗?因为我已经通过管理CustomTabs布局来实现所有点击。我只是想让它左侧滚动。 – NehaK

+0

我通过在recyclerView中使用整个CustomTabManager来解决此问题。 – NehaK