1

I want to create an Excel type layout where there is infinite scroll vertically. There are fixed number of columns horizontally, but they should be scrollable.

enter image description here

I tried the below code

 <HorizontalScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">
<android.support.v7.widget.RecyclerView
        android:id="@+id/table_data_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</HorizontalScrollView>

If I used the above code, then I am able to scroll vertically, but the columns are not scrollable.

Even giving fixed height in the xml for HorizontalScrollView and RecyclerView, the columns do not scroll.

Finally, I found an answer here, where it was advised to extend the RecyclerView and calculate the height dynamically.

 public class MySmartRecyclerView extends RecyclerView {

  public MySmartRecyclerView(Context context) {
    super(context);
  }

  public MySmartRecyclerView(Context context, AttributeSet attrs) {
    super(context, attrs);
  }

  public MySmartRecyclerView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
  }

  @Override
  public boolean canScrollHorizontally(int direction) {
    return false;
  }

  @Override
  public int getMinimumWidth() {
    return computedWidth;
  }

  @Override
  protected void onMeasure(int widthSpec, int heightSpec) {
    super.onMeasure(widthSpec, heightSpec);
    setMeasuredDimension(computedWidth, getMeasuredHeight());
  }

  @Override
  protected int getSuggestedMinimumWidth() {
    return computedWidth;
  }
}

So is this the only way, this can be achieved? Or is there any other way to achieve this. For RecyclerView inside ScrollView there is NestedScrollView, but no such thing for HorizontalScrollView.

Any pointers will be appreciated. TIA.

Community
  • 1
  • 1
thedarkpassenger
  • 7,158
  • 3
  • 37
  • 61

2 Answers2

2

There is one alternate solution. You can use this library.

Ankit Aman
  • 999
  • 6
  • 15
0

You want to do Ehhhh? Like the guy said, use library. You need and have normal easy to use solutions.

EDIT:

Okay my bad. You want to infinite scroll vertically, not excel. I'm back from excel topic:

at onScroll listener, you should incriment endlessly the totalItemCount, you do it with double recurssion. From within the function of listener, you call to another listner whereas you call it by a function in the middle, which also increments that number before calling to the same listener again. You simply edit the view and re-attach the listener.

Vitali Pom
  • 602
  • 1
  • 8
  • 29