-1

Actually I'm trying to use recyclerview as a viewpager which is working fine by the help of PagerSnapHelper() class . But now the problem is how can I force recyclerview to change item heights dynamically and not show white space . Now when I try to load drawable pictures of two different sizes i.e a small and a bigger at first the smaller one is having correct size but when I scroll to next and then first some white space is shown below the imageView.You can see aforementioned problems in the given pictures.

first image second bigger image white spaced first image

XML:

<android.support.v7.widget.RecyclerView
    android:id="@+id/rView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    />

Recyclerview Items:

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/recyclerImgView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
 />
</FrameLayout>

Adapter Code:

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    Glide.with(ctx).load(pics.get(position)).into(holder.imageView);
}

Activity Code:

rView.setLayoutManager(new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL,false));
    rView.setAdapter(adp);
    SnapHelper snapHelper = new PagerSnapHelper();
    snapHelper.attachToRecyclerView(rView);
Srinivas Nahak
  • 1,846
  • 4
  • 20
  • 45

2 Answers2

0

you can change image view width and height like below code..

<ImageView

android:id="@+id/recyclerImgView" android:layout_width="wrap_content" android:layout_height="wrap_content" />

and recycler view change height like below code..

<android.support.v7.widget.RecyclerView
android:id="@+id/rView"
android:layout_width="@dimen/_100sdp"
android:layout_height="@dimen/_100sdp"
/>

add this below dependency into app level gradle file and give size is same all the device like below ..

  implementation 'com.intuit.sdp:sdp-android:1.0.4'
  • thanks for your time sir but it's not changing anything – Srinivas Nahak Apr 20 '18 at 13:28
  • then give fixed height and width to image view . –  Apr 20 '18 at 13:29
  • also give image view height and width match_parent .it show full but image strach. –  Apr 20 '18 at 13:31
  • Actually I wanna change the view's height dynamically so that every image can be shown by it's original size . If I'll set any fixed size then my motto won't be accomplished. – Srinivas Nahak Apr 20 '18 at 13:35
  • add below dependency into app level gradle file and define height and width this format and i change put in my code.. implementation 'com.intuit.sdp:sdp-android:1.0.4' . give size is same as all device.. –  Apr 20 '18 at 13:36
  • android:layout_width="@dimen/_100sdp" android:layout_height="@dimen/_100sdp" –  Apr 20 '18 at 13:38
0

Change your Recyclerview Items with this code by adding scaleType in your image view

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="150dp">

 <ImageView 
 android:id="@+id/recyclerImgView"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:scaleType="fitXY"/>
</FrameLayout>