user2805004 user2805004 - 1 year ago 139
Android Question

RecyclerView does not fully expand to show all elements

I've created an EditText, a Button and a RecyclerView (composed of 1 TextView and 1 ImageView children) to add TextViews that looks like this . In the EditText at the top, users may enter text and hit the + button. This adds their text to a List(String) which is used to update the RecyclerView. The user may hit the x at the right to delete an entry from the RecyclerView. Here is an image of the overall fragment layout

The issue, which you can see in the image, is that after a few submissions, the RecyclerView stops expanding and remains at a fixed size (notice the small blip in the bottom right). You may scroll in the RecyclerView to view the items, items are still added to it, but it will not expand to the full size (the one in the image has 20+ items). If I delete an item, the height grows for some reason but it still won't display all elements and it shrinks back when I add a new item.

Things I've tried

Here is the RecyclerView code. The heirarchy goes


All heights and widths are set to match parent, all orientations to vertical:


The code to add an entry to the RecyclerView (outside of the adapter):

ingredientsButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (ingredientsText.getText().toString().length() > 0) {

And, finally, the code to delete an entry from the RecyclerView (inside the RV adapter):

cancelImage.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mAdapter.notifyItemRangeChanged(getAdapterPosition(), mIngredients.size());
if(mAdapter.getItemCount() == 0)

Any assistance would be GREATLY appreciated, as I can't figure this out for the life of me!

Answer Source

use NestedScrollView instead of ScrollView and setNestedScrollEnabled(false) on the RecyclerView

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download