Reputation: 1713
I have a problem with my button, which is in the bottom of the screen. I want to appear it only after scroll end. The difficulty is that my layout designed like following
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/all">
<include
android:id="@+id/toolbar"
layout="@layout/new_toolbar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/question_steps"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar"
app:tabIndicatorHeight="0dp"
android:visibility="gone"
app:tabTextColor="@color/tab_text"
app:tabSelectedTextColor="@color/orange_text"/>
<ProgressBar
android:id="@+id/questionnaire_progress"
style="@style/Base.Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="4dp"
android:max="5"
android:progress="1"
android:progressDrawable="@drawable/questionnaire_progress"
app:layout_anchor="@+id/toolbar"
app:layout_anchorGravity="bottom|center" />
<QuestionnairePager
android:id="@+id/questions_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="59dp"
app:layout_anchorGravity="center|bottom"
app:layout_anchor="@id/questionnaire_progress"
app:layout_scrollFlags="scroll|enterAlways"/>
<android.widget.Button
android:id="@+id/next"
style="@style/styleCustomSolidButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:drawableEnd="@drawable/goto_white"
android:text="@string/submit"
android:visibility="visible"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_anchor="@+id/questions_content"
app:layout_anchorGravity="bottom|center" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
In my ViewPager
, which is QuestionnairePager
, I have fragment
with ScrollView
and I want to display my button only after scroll reaches the end. How can I make it? Could someone give me any suggestions.
Upvotes: 1
Views: 50
Reputation: 702
try this
scrollView.getViewTreeObserver()
.addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() {
if (scrollView.getChildAt(0).getBottom()
<= (scrollView.getHeight() + scrollView.getScrollY())) {
//scroll view is at bottom show your view
} else {
//scroll view is not at bottom hide your view
}
}
});
Upvotes: 2