Reputation: 387
I have a view pager and have 3 fragments. These 3 fragments are recycler view.
I would like to when I drag to the next page, the scroll bar will be disappeared. But I don't want to use setVerticalScrollBarEnabled
. Because when called this method, the main content items will be scaled up. I think the reason is the scroll bar width is 4dp. So the main content items will be scaled up. I don't like this scale up effect.
I also tried setVerticalScrollbarThumbDrawable
with transparent colour. But this method need to add this condition Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
.
Anybody can give me some suggestions. Thanks a lot.
public void SetRecyclerViewScrollBar(boolean enable) {
if(this.mRecyclerView != null) {
this.mAdapter.notifyDataSetChanged();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if(!enable) {
this.mRecyclerView.setVerticalScrollbarThumbDrawable(this.mContext.getDrawable(R.drawable.scrollbar_transparent));
this.mRecyclerView.setVerticalScrollbarTrackDrawable(this.mContext.getDrawable(R.drawable.vertical_scrollview_track_transparent));
} else {
this.mRecyclerView.setVerticalScrollbarThumbDrawable(this.mContext.getDrawable(R.drawable.scrollbar));
this.mRecyclerView.setVerticalScrollbarTrackDrawable(this.mContext.getDrawable(R.drawable.vertical_scrollview_track));
}
}
}
}
Upvotes: 1
Views: 1904
Reputation: 19273
make some semi transparent scroll thumb drawable and add this:
android:scrollbarStyle="insideOverlay"
or Java/Kotlin side:
scrollableView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
this will make your thumb won't take space and will be drawn on top of your list/content. check out this pic how different styles behaves. and then you may use setVerticalScrollBarEnabled
, space for your content (whole screen width) won't change and won't be redrawn (thus scaled up)
Upvotes: 2
Reputation: 137
Try use this in your layout file.
android:scrollbars="none"
It should be like this.
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
...
Upvotes: 0
Reputation: 309
If it's not important show scrollbar try to add this in your XML it will disappear scrollbar
android:scrollbars="none"
Upvotes: 1