Java Code Examples for android.support.v7.widget.LinearLayoutManager#scrollToPositionWithOffset()

The following examples show how to use android.support.v7.widget.LinearLayoutManager#scrollToPositionWithOffset() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java    From MaterialViewPager with Apache License 2.0 6 votes vote down vote up
public static void scrollTo(Object scroll, float yOffset) {
    if (scroll instanceof RecyclerView) {
        //RecyclerView.scrollTo : UnsupportedOperationException
        //Moved to the RecyclerView.LayoutManager.scrollToPositionWithOffset
        //Have to be instanceOf RecyclerView.LayoutManager to work (so work with RecyclerView.GridLayoutManager)
        final RecyclerView.LayoutManager layoutManager = ((RecyclerView) scroll).getLayoutManager();
        if (layoutManager instanceof LinearLayoutManager) {
            LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
            linearLayoutManager.scrollToPositionWithOffset(0, (int) -yOffset);
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
            staggeredGridLayoutManager.scrollToPositionWithOffset(0, (int) -yOffset);
        }
    } else if (scroll instanceof NestedScrollView) {
        ((NestedScrollView) scroll).scrollTo(0, (int) yOffset);
    }
}
 
Example 2
Source File: ExcelPanel.java    From excelPanel with Apache License 2.0 6 votes vote down vote up
static void fastScrollVertical(int amountAxis, RecyclerView recyclerView) {
    LinearLayoutManager linearLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
    if (indexHeight == null) {
        indexHeight = new TreeMap<>();
        //call this method the OnScrollListener's onScrolled will be called,but dx and dy always be zero.
        linearLayoutManager.scrollToPositionWithOffset(0, -amountAxis);
    } else {
        int total = 0, count = 0;
        Iterator<Integer> iterator = indexHeight.keySet().iterator();
        while (null != iterator && iterator.hasNext()) {
            int height = indexHeight.get(iterator.next());
            if (total + height >= amountAxis) {
                break;
            }
            total += height;
            count++;
        }
        linearLayoutManager.scrollToPositionWithOffset(count, -(amountAxis - total));
    }
}
 
Example 3
Source File: CardPlayerFragment.java    From Orin with GNU General Public License v3.0 6 votes vote down vote up
private void setUpRecyclerView() {
    recyclerViewDragDropManager = new RecyclerViewDragDropManager();
    final GeneralItemAnimator animator = new RefactoredDefaultItemAnimator();

    playingQueueAdapter = new PlayingQueueAdapter(
            ((AppCompatActivity) getActivity()),
            MusicPlayerRemote.getPlayingQueue(),
            MusicPlayerRemote.getPosition(),
            R.layout.item_list,
            false,
            null);
    wrappedAdapter = recyclerViewDragDropManager.createWrappedAdapter(playingQueueAdapter);

    layoutManager = new LinearLayoutManager(getActivity());

    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(wrappedAdapter);
    recyclerView.setItemAnimator(animator);

    recyclerViewDragDropManager.attachRecyclerView(recyclerView);

    layoutManager.scrollToPositionWithOffset(MusicPlayerRemote.getPosition() + 1, 0);
}
 
Example 4
Source File: NowPlayingFragment.java    From Popeens-DSub with GNU General Public License v3.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void scrollToCurrent() {
	if (getDownloadService() == null || songListAdapter == null) {
		scrollWhenLoaded = true;
		return;
	}

	// Try to get position of current playing/downloading
	int position = songListAdapter.getItemPosition(currentPlaying);
	if(position == -1) {
		DownloadFile currentDownloading = getDownloadService().getCurrentDownloading();
		position = songListAdapter.getItemPosition(currentDownloading);
	}

	// If found, scroll to it
	if(position != -1) {
		// RecyclerView.scrollToPosition just puts it on the screen (ie: bottom if scrolled below it)
		LinearLayoutManager layoutManager = (LinearLayoutManager) playlistView.getLayoutManager();
		layoutManager.scrollToPositionWithOffset(position, 0);
	}
}
 
Example 5
Source File: ItemAdapter.java    From IdeaTrackerPlus with MIT License 6 votes vote down vote up
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View layoutView = LayoutInflater.from(parent.getContext()).inflate(mLayoutId, parent, false);

    //create Recycler here
    MyRecyclerView recyclerView = (MyRecyclerView) layoutView.findViewById(R.id.horizontal_recycler_view);
    recyclerView.reboot(); //in case it's recycled

    // Create the right adapter for the recycler view
    HorizontalAdapter horizontalAdapter;
    horizontalAdapter = new HorizontalAdapter(recyclerView.getContext(), "", mTabNumber, mDarkTheme);

    // Set up the manager and adapter of the recycler view
    LinearLayoutManager horizontalLayoutManager = new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false);
    horizontalLayoutManager.scrollToPositionWithOffset(1, 0);
    recyclerView.setTag(0);
    recyclerView.setLayoutManager(horizontalLayoutManager);
    recyclerView.setAdapter(horizontalAdapter);
    recyclerView.setUp();

    return new ViewHolder(layoutView, recyclerView);
}
 
Example 6
Source File: SortUtil.java    From DMusic with Apache License 2.0 6 votes vote down vote up
public void onChange(int index, String c, RecyclerView recyclerView) {
    if (recyclerView == null || letterMap == null) {
        return;
    }
    RecyclerView.LayoutManager lm = recyclerView.getLayoutManager();
    if (lm == null || !(lm instanceof LinearLayoutManager)) {
        return;
    }
    LinearLayoutManager manager = (LinearLayoutManager) lm;
    if (index == 0) {
        manager.scrollToPositionWithOffset(0, 0);//置顶
        return;
    }
    int[] value = letterMap.get(c);
    if (value != null) {
        manager.scrollToPositionWithOffset(value[0] + 2, 0);//+1 refresh header、+1 header
    }
}
 
Example 7
Source File: MainActivity.java    From googlecalendar with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId()==R.id.action_favorite){
        final LocalDate localDate=LocalDate.now();

       final LinearLayoutManager linearLayoutManager= (LinearLayoutManager) mNestedView.getLayoutManager();
       mNestedView.stopScroll();
        if (indextrack.containsKey(new LocalDate(localDate.getYear(),localDate.getMonthOfYear(),localDate.getDayOfMonth()))){

            final Integer val=indextrack.get(new LocalDate(localDate.getYear(),localDate.getMonthOfYear(),localDate.getDayOfMonth()));

           if (isAppBarExpanded()){
               calendarView.setCurrentmonth(new LocalDate());
               expandedfirst=val;
               topspace=20;
               linearLayoutManager.scrollToPositionWithOffset(val,20);
               EventBus.getDefault().post(new MonthChange(localDate,0));
               month=localDate.getDayOfMonth();
               lastdate=localDate;
           }
           else {
               calendarView.setCurrentmonth(new LocalDate());
               expandedfirst=val;
               topspace=20;
               linearLayoutManager.scrollToPositionWithOffset(val,20);
               EventBus.getDefault().post(new MonthChange(localDate,0));
               month=localDate.getDayOfMonth();
               lastdate=localDate;

           }


        }

    }
    return super.onOptionsItemSelected(item);

}
 
Example 8
Source File: LocalFragment.java    From Yuan-SxMusic with Apache License 2.0 5 votes vote down vote up
private void initLocalRecycler() {
    mLocalSongsList = new ArrayList<>();
    layoutManager = new LinearLayoutManager(getActivity());
    mLocalSongsList.clear();
    mLocalSongsList.addAll(LitePal.findAll(LocalSong.class));
    if (mLocalSongsList.size() == 0) {
        mRecycler.setVisibility(View.GONE);
        mEmptyViewLinear.setVisibility(View.VISIBLE);
    } else {
        mEmptyViewLinear.setVisibility(View.GONE);
        mRecycler.setVisibility(View.VISIBLE);
        mRecycler.setLayoutManager(layoutManager);
        //令recyclerView定位到当前播放的位置
        songAdapter = new SongAdapter(mActivity, mLocalSongsList);
        mRecycler.setAdapter(songAdapter);
        if (FileUtil.getSong() != null) {
            layoutManager.scrollToPositionWithOffset(FileUtil.getSong().getPosition() - 4, mRecycler.getHeight());
        }
        songAdapter.setOnItemClickListener(position -> {
            //将点击的序列化到本地
            LocalSong mp3Info = mLocalSongsList.get(position);
            Song song = new Song();
            song.setSongName(mp3Info.getName());
            song.setSinger(mp3Info.getSinger());
            song.setUrl(mp3Info.getUrl());
            song.setDuration(mp3Info.getDuration());
            song.setPosition(position);
            song.setOnline(false);
            song.setSongId(mp3Info.getSongId());
            song.setListType(Constant.LIST_TYPE_LOCAL);
            FileUtil.saveSong(song);
            mPlayStatusBinder.play(Constant.LIST_TYPE_LOCAL);
        });

    }
}
 
Example 9
Source File: ActivityELMe.java    From RxTools-master with Apache License 2.0 5 votes vote down vote up
@Override
public void onLeftItemSelected(int position, ModelDishMenu menu) {
    int sum = 0;
    for (int i = 0; i < position; i++) {
        sum += mModelDishMenuList.get(i).getModelDishList().size() + 1;
    }
    LinearLayoutManager layoutManager = (LinearLayoutManager) mRightMenu.getLayoutManager();
    layoutManager.scrollToPositionWithOffset(sum, 0);
    leftClickType = true;
}
 
Example 10
Source File: WidgetsRecyclerView.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Maps the touch (from 0..1) to the adapter position that should be visible.
 */
@Override
public String scrollToPositionAtProgress(float touchFraction) {
    // Skip early if widgets are not bound.
    if (mWidgets == null) {
        return "";
    }

    // Skip early if there are no widgets.
    int rowCount = mWidgets.getPackageSize();
    if (rowCount == 0) {
        return "";
    }

    // Stop the scroller if it is scrolling
    stopScroll();

    getCurScrollState(mScrollPosState);
    float pos = rowCount * touchFraction;
    int availableScrollHeight = getAvailableScrollHeight(rowCount, mScrollPosState.rowHeight);
    LinearLayoutManager layoutManager = ((LinearLayoutManager) getLayoutManager());
    layoutManager.scrollToPositionWithOffset(0, (int) -(availableScrollHeight * touchFraction));

    int posInt = (int) ((touchFraction == 1)? pos -1 : pos);
    PackageItemInfo p = mWidgets.getPackageItemInfo(posInt);
    return p.titleSectionName;
}
 
Example 11
Source File: Utils.java    From guitar-tuner with Apache License 2.0 5 votes vote down vote up
public static void scrollToPosition(RecyclerView recyclerView, int position) {
    LinearLayoutManager lm = (LinearLayoutManager) recyclerView.getLayoutManager();
    int recyclerWidth = recyclerView.getWidth();


    View itemView = lm.findViewByPosition(position);
    if (itemView != null) {
        int viewWidth = itemView.getWidth();
        lm.scrollToPositionWithOffset(position, -(recyclerWidth - viewWidth) / 2);
    }
}
 
Example 12
Source File: GridStyleActivity.java    From ZoomPreviewPicture with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
    setContentView(R.layout.activity_recycler);
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
    mRvPostLister = (RecyclerView) findViewById(R.id.rv_post_list);
    final LinearLayoutManager manager = new LinearLayoutManager(this);
    mRvPostLister.setLayoutManager(manager);
    mPostList = new ArrayList<>();
    for (int i = 0; i < 29; i++) {
        List<UserViewInfo> imgUrls = new ArrayList<>();
        UserViewInfo userViewInfo;
        Random ss=new Random();

        for (int j = 0; j <ss.nextInt(9); j++) {
            userViewInfo=new UserViewInfo(     ImageUrlConfig.getUrls().get(j));
            imgUrls.add(userViewInfo);
        }
        Post post = new Post("Am I handsome? Am I handsome? Am I handsome?", imgUrls);
        mPostList.add(post);
    }

    mNineImageAdapter = new PostAdapter(this, mPostList, NineGridImageView.STYLE_GRID);
    mRvPostLister.setAdapter(mNineImageAdapter);
    manager.scrollToPositionWithOffset(5, 0);
    mRvPostLister.post(new Runnable() {
        @Override
        public void run() {
            View view = manager.findViewByPosition(1);
            if (view != null) System.out.println(view.getMeasuredHeight());
        }
    });
}
 
Example 13
Source File: PlayingQueueFragment.java    From RetroMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
private void setUpRecyclerView() {
    mRecyclerViewDragDropManager = new RecyclerViewDragDropManager();
    final GeneralItemAnimator animator = new RefactoredDefaultItemAnimator();

    mPlayingQueueAdapter = new PlayingQueueAdapter(
            (AppCompatActivity) getActivity(),
            MusicPlayerRemote.getPlayingQueue(),
            MusicPlayerRemote.getPosition(),
            R.layout.item_list,
            false,
            null);
    mWrappedAdapter = mRecyclerViewDragDropManager.createWrappedAdapter(mPlayingQueueAdapter);

    mLayoutManager = new LinearLayoutManager(getContext());

    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setAdapter(mWrappedAdapter);
    mRecyclerView.setItemAnimator(animator);

    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
               /* if (recyclerView.canScrollVertically(RecyclerView.NO_POSITION)) {
                    mAppBarLayout.setElevation(5f);
                } else {
                    mAppBarLayout.setElevation(0f);
                }*/
            }
        }
    });

    mRecyclerViewDragDropManager.attachRecyclerView(mRecyclerView);
    mLayoutManager.scrollToPositionWithOffset(MusicPlayerRemote.getPosition() + 1, 0);
}
 
Example 14
Source File: GridStyleActivity.java    From NineGridImageView with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
    setContentView(R.layout.activity_recycler);
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));

    mRvPostLister = (RecyclerView) findViewById(R.id.rv_post_list);
    final LinearLayoutManager manager = new LinearLayoutManager(this);
    mRvPostLister.setLayoutManager(manager);

    mPostList = new ArrayList<>();
    for (int i = 0; i < 18; i++) {
        List<String> imgUrls = new ArrayList<>();
        imgUrls.addAll(Arrays.asList(IMG_URL_LIST).subList(0, i % 9));
        Post post = new Post("Am I handsome? Am I handsome? Am I handsome?", imgUrls);
        mPostList.add(post);
    }

    mNineImageAdapter = new PostAdapter(this, mPostList, NineGridImageView.STYLE_GRID);
    mRvPostLister.setAdapter(mNineImageAdapter);

    manager.scrollToPositionWithOffset(5, 0);
    mRvPostLister.post(new Runnable() {
        @Override
        public void run() {
            View view = manager.findViewByPosition(1);
            if (view != null) System.out.println(view.getMeasuredHeight());
        }
    });
}
 
Example 15
Source File: AllAppsRecyclerView.java    From Trebuchet with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Maps the touch (from 0..1) to the adapter position that should be visible.
 */
@Override
public String scrollToPositionAtProgress(float touchFraction) {
    int rowCount = mApps.getNumAppRows();
    if (rowCount == 0) {
        return "";
    }

    // Stop the scroller if it is scrolling
    stopScroll();

    // Find the fastscroll section that maps to this touch fraction
    List<AlphabeticalAppsList.FastScrollSectionInfo> fastScrollSections =
            mApps.getFastScrollerSections();
    AlphabeticalAppsList.FastScrollSectionInfo lastInfo = fastScrollSections.get(0);
    if (mScrollBarMode == FAST_SCROLL_BAR_MODE_DISTRIBUTE_BY_ROW) {
        for (int i = 1; i < fastScrollSections.size(); i++) {
            AlphabeticalAppsList.FastScrollSectionInfo info = fastScrollSections.get(i);
            if (info.touchFraction > touchFraction) {
                break;
            }
            lastInfo = info;
        }
    } else if (mScrollBarMode == FAST_SCROLL_BAR_MODE_DISTRIBUTE_BY_SECTIONS){
        lastInfo = fastScrollSections.get((int) (touchFraction * (fastScrollSections.size() - 1)));
    } else {
        throw new RuntimeException("Unexpected scroll bar mode");
    }

    // Reset the last focused section
    if (mPrevFastScrollFocusedSection != lastInfo.sectionInfo) {
        setSectionFastScrollDimmed(mPrevFastScrollFocusedPosition, true, true);
        clearSectionFocusedItems();
    }

    mPrevFastScrollFocusedPosition = lastInfo.fastScrollToItem.position;
    mPrevFastScrollFocusedSection = lastInfo.sectionInfo;

    getCurScrollState(mScrollPosState);
    if (mFastScrollMode == FAST_SCROLL_MODE_JUMP_TO_FIRST_ICON) {
        smoothSnapToPosition(mPrevFastScrollFocusedPosition, mScrollPosState);

        setSectionFastScrollDimmed(mPrevFastScrollFocusedPosition, false, true);
        setSectionFastScrollFocused(mPrevFastScrollFocusedPosition);
    } else if (mFastScrollMode == FAST_SCROLL_MODE_FREE_SCROLL) {
        // Map the touch position back to the scroll of the recycler view
        int availableScrollHeight = getAvailableScrollHeight(rowCount, mScrollPosState.rowHeight);
        LinearLayoutManager layoutManager = (LinearLayoutManager) getLayoutManager();
        layoutManager.scrollToPositionWithOffset(0, (int) -(availableScrollHeight * touchFraction));

        setSectionFastScrollFocused(mPrevFastScrollFocusedPosition);
    } else {
        throw new RuntimeException("Unexpected fast scroll mode");
    }
    return lastInfo.sectionName;
}
 
Example 16
Source File: FastScrollRecyclerView.java    From FastScroll-RecyclerView with Apache License 2.0 4 votes vote down vote up
/**
 * <p>Maps the touch (from 0..1) to the adapter position that should be visible.</p>
 *
 * <p>Override in each subclass of this base class.</p>
 */
public String scrollToPositionAtProgress(float touchFraction) {
  int itemCount = getAdapter().getItemCount();
  if (itemCount == 0) {
    return "";
  }
  int spanCount = 1;
  int rowCount = itemCount;
  if (getLayoutManager() instanceof GridLayoutManager) {
    spanCount = ((GridLayoutManager) getLayoutManager()).getSpanCount();
    rowCount = (int) Math.ceil((double) rowCount / spanCount);
  }

  // Stop the scroller if it is scrolling
  stopScroll();

  getCurScrollState(scrollPositionState);

  float itemPos = itemCount * touchFraction;

  int availableScrollHeight = getAvailableScrollHeight(rowCount, scrollPositionState.rowHeight);

  //The exact position of our desired item
  int exactItemPos = (int) (availableScrollHeight * touchFraction);

  //Scroll to the desired item. The offset used here is kind of hard to explain.
  //If the position we wish to scroll to is, say, position 10.5, we scroll to position 10,
  //and then offset by 0.5 * rowHeight. This is how we achieve smooth scrolling.
  LinearLayoutManager layoutManager = ((LinearLayoutManager) getLayoutManager());
  layoutManager.scrollToPositionWithOffset(spanCount * exactItemPos / scrollPositionState.rowHeight,
      -(exactItemPos % scrollPositionState.rowHeight));

  if (!(getAdapter() instanceof SectionedAdapter)) {
    return "";
  }

  int posInt = (int) ((touchFraction == 1) ? itemPos - 1 : itemPos);

  SectionedAdapter sectionedAdapter = (SectionedAdapter) getAdapter();
  return sectionedAdapter.getSectionName(posInt);
}
 
Example 17
Source File: RecycleViewScrollHelper.java    From Android with MIT License 4 votes vote down vote up
public void scrollToPosition(int posi, int top) {
    LinearLayoutManager layoutManager = (LinearLayoutManager) mRvScroll.getLayoutManager();
    layoutManager.scrollToPositionWithOffset(posi - 1, top);// -1==>Starting from 0 to calculate
}
 
Example 18
Source File: ConversationsOverviewFragment.java    From Conversations with GNU General Public License v3.0 4 votes vote down vote up
private void setScrollPosition(ScrollState scrollPosition) {
	if (scrollPosition != null) {
		LinearLayoutManager layoutManager = (LinearLayoutManager) binding.list.getLayoutManager();
		layoutManager.scrollToPositionWithOffset(scrollPosition.position, scrollPosition.offset);
	}
}
 
Example 19
Source File: FastScroller.java    From Popeens-DSub with GNU General Public License v3.0 4 votes vote down vote up
private void setRecyclerViewPosition(float y) {
	if(recyclerView != null) {
		if(recyclerView.getChildCount() == 0) {
			return;
		}

		int itemCount = recyclerView.getAdapter().getItemCount();
		float proportion = getValueInRange(0, 1f, y / (float) height);

		float targetPosFloat = getValueInRange(0, itemCount - 1, proportion * (float)itemCount);
		int targetPos = (int) targetPosFloat;

		// Immediately make sure that the target is visible
		LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
		// layoutManager.scrollToPositionWithOffset(targetPos, 0);
		View firstVisibleView = recyclerView.getChildAt(0);

		// Calculate how far through this position we are
		int columns = Math.round(recyclerView.getWidth() / firstVisibleView.getWidth());
		int firstVisiblePosition = recyclerView.getChildPosition(firstVisibleView);
		int remainder = (targetPos - firstVisiblePosition) % columns;
		float offsetPercentage = (targetPosFloat - targetPos + remainder) / columns;
		if(offsetPercentage < 0) {
			offsetPercentage = 1 + offsetPercentage;
		}
		int firstVisibleHeight = firstVisibleView.getHeight();
		if(columns > 1) {
			firstVisibleHeight += (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, GridSpacingDecoration.SPACING, firstVisibleView.getResources().getDisplayMetrics());
		}
		int offset = (int) (offsetPercentage * firstVisibleHeight);

		layoutManager.scrollToPositionWithOffset(targetPos, -offset);
		onUpdateScroll(1, 1);

		try {
			String bubbleText = null;
			RecyclerView.Adapter adapter = recyclerView.getAdapter();
			if(adapter instanceof BubbleTextGetter) {
				bubbleText = ((BubbleTextGetter) adapter).getTextToShowInBubble(targetPos);
			}

			if(bubbleText == null) {
				visibleBubble = false;
				bubble.setVisibility(View.INVISIBLE);
			} else {
				bubble.setText(bubbleText);
				bubble.setVisibility(View.VISIBLE);
				visibleBubble = true;
			}
		} catch(Exception e) {
			Log.e(TAG, "Error getting text for bubble", e);
		}
	}
}
 
Example 20
Source File: FastScrollRecyclerView.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Maps the touch (from 0..1) to the adapter position that should be visible.
 */
public String scrollToPositionAtProgress(float touchFraction) {
    int itemCount = getAdapter().getItemCount();
    if (itemCount == 0) {
        return "";
    }
    int spanCount = 1;
    int rowCount = itemCount;
    if (getLayoutManager() instanceof GridLayoutManager) {
        spanCount = ((GridLayoutManager) getLayoutManager()).getSpanCount();
        rowCount = (int) Math.ceil((double) rowCount / spanCount);
    }

    // Stop the scroller if it is scrolling
    stopScroll();

    getCurScrollState(mScrollPosState);

    float itemPos = itemCount * touchFraction;

    int availableScrollHeight = getAvailableScrollHeight(rowCount, mScrollPosState.rowHeight, 0);

    //The exact position of our desired item
    int exactItemPos = (int) (availableScrollHeight * touchFraction);

    //Scroll to the desired item. The offset used here is kind of hard to explain.
    //If the position we wish to scroll to is, say, position 10.5, we scroll to position 10,
    //and then offset by 0.5 * rowHeight. This is how we achieve smooth scrolling.
    LinearLayoutManager layoutManager = ((LinearLayoutManager) getLayoutManager());
    layoutManager.scrollToPositionWithOffset(spanCount * exactItemPos / mScrollPosState.rowHeight,
            -(exactItemPos % mScrollPosState.rowHeight));

    if (!(getAdapter() instanceof SectionedAdapter)) {
        return "";
    }

    int posInt = (int) ((touchFraction == 1) ? itemPos - 1 : itemPos);

    SectionedAdapter sectionedAdapter = (SectionedAdapter) getAdapter();
    return sectionedAdapter.getSectionName(posInt);
}