Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
172 views
in Technique[技术] by (71.8m points)

android - Margin to the scrollbar only (not to recyclerview) on recyclerview

My recycler view lies under my toolbar, as you can see from the first picture. However, I have a scrollbar on the right side of it. I have to give a margin-top to this scrollbar. I have tried with giving style. And I know about clip padding with padding-top and padding-bottom, however, I need this exactly. Are there any ways to make it real?

This is my problem

The result that I want

P.S. I know that it is not the best practice. I would appreciate any help. It is one of my first questions, don't judge me so strong. :)

My main XML file

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="?attr/background1"
android:keepScreenOn="true"
tools:context=".ui.main.HomeActivity">

<androidx.viewpager.widget.ViewPager
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/pager" />

<include layout="@layout/toolbar_sura_detail" />

<include layout="@layout/player" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

My Fragment XML inside ViewPager

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="?attr/background1">

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/kuranDetailList"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:isScrollContainer="false"
    android:fitsSystemWindows="true"
    android:scrollbarSize="2dp"
    android:scrollbarThumbVertical="@drawable/thumbforrecycle"
    android:scrollbars="vertical"
    android:orientation="vertical" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
question from:https://stackoverflow.com/questions/65857017/margin-to-the-scrollbar-only-not-to-recyclerview-on-recyclerview

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try using this structure in your main XML and add scrolling layout behaviour for ViewPager

<androidx.coordinatorlayout.widget.CoordinatorLayout...
<com.google.android.material.appbar.AppBarLayout...
   <androidx.appcompat.widget.Toolbar...

</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:id="@+id/pager"
  app:layout_behavior = "com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"/>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...