2

I have one activity that includes some textviews and one recyclerView that has images displayed with Glide. I had a problem that recyclerview has its own scroller that I don't need.

Then I added this: android:nestedScrollingEnabled="false" to RecyclerView xml

according to RecyclerView need to scroll along the activity

and now recyclerview is scrolling along with activity, but now there is another problem. Not all images are visible. It looks like that RecyclerView does not know what is the size of all images inside it while it is inflating. I am using Glide for displaying images, and image item has fixed size 250dp.

If I remove nestedScrollingEnabled attribute, then all images are visible but I need to scroll inside that recyclerView.

this is my recyclerview

<?xml version="1.0" encoding="utf-8"?>

<ScrollView 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="fill_parent"
    android:layout_height="fill_parent">

    <android.support.constraint.ConstraintLayout 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:id="@+id/activity_prikazi_vest"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin1"
        android:paddingRight="@dimen/activity_horizontal_margin1"
        android:paddingTop="@dimen/activity_horizontal_margin1"
        android:scrollbars="vertical"
        tools:context="myapp.app.news">

----------------here are some textviews----------------------


    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view_images"
        android:nestedScrollingEnabled="false"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="16dp"
        android:scrollbars="none"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintVertical_bias="0.0" />

    </android.support.constraint.ConstraintLayout>
</ScrollView>

this is setting I use for Glide

RequestOptions options = new RequestOptions()
        .centerCrop()
        .placeholder(R.drawable.image1)
        .error(R.drawable.image2)
        .priority(Priority.HIGH);

Update:

to have smooth scroll please use this inside recyclerview

android:nestedScrollingEnabled="false"
android:isScrollContainer="false"
emir
  • 1,336
  • 1
  • 14
  • 33

1 Answers1

1

Update:

Change ScrollView to android.support.v4.widget.NestedScrollView, and remove android:nestedScrollingEnabled attribute. NestedScrollView is layout that can contains scrollable children.


One option is change centerCrop() to fitCenter().

RequestOptions options = new RequestOptions()
    .fitCenter()
    .placeholder(R.drawable.image1)
    .error(R.drawable.image2)
    .priority(Priority.HIGH);

Details about glide option: https://github.com/bumptech/glide/wiki/Transformations

center crop fit center

Details about centerCrop, fitCenter https://robots.thoughtbot.com/android-imageview-scaletype-a-visual-guide

Stanley Ko
  • 3,383
  • 3
  • 34
  • 60
  • It changed the appearance of an image, but still, not all images are displayed. Only 3 images are visible. When I turn scrolling on, I can see all images, but I need to scroll them inside this activity scroller which is very confusing to the user. – emir Apr 10 '18 at 01:13
  • Switching to NestedScrollView solved the problem, then I just needed to allow vertical slider and that is all. Thanks – emir Apr 10 '18 at 08:37
  • There is only one more problem with scrolling. It is smooth while I am going to bottom, and then when I go up, it is not smooth and it does not continue scrolling when I swipe my finger but stops at the moment I lift my finger. – emir Apr 10 '18 at 08:48