[SOLVED]
The whole trick is to manually set the bandwidth of the RecyclerView, as it refuses to accept WRAP_CONTENT and is always as wide as the screen. Trick:
public class SmartRecyclerView extends RecyclerView { public int computedWidth = <needs to be set from outside> public SmartRecyclerView(Context context) { super(context); } public SmartRecyclerView(Context context, AttributeSet attrs) { super(context, attrs); } public SmartRecyclerView(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; } }
and then just:
HorizontalScrollView myScroll = ... SmartRecyclerView recyclerView = new SmartRecyclerView(...) ... recyclerView.computedWidth = myNeededWidth; myScroll.addView(recyclerView);
And he WORKS! Happy coding ...
working code example: https://dl.dropboxusercontent.com/u/79978438/RecyclerView_ScrollView.zip
source share