1

I have a project i am developing but i have come to face a problem with a large gap appearing between two items on my android application ,i had tried to look on every previous suggestions here on how to solve the problem but none has worked for me

Here is my Layout that causes problems

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:layout_height="match_parent"
android:orientation="horizontal">

<android.support.v7.widget.RecyclerView
    android:id="@+id/prodct_list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="false"
    android:scaleType="fitXY"
    android:padding="0dp"
    android:adjustViewBounds="true"/>

<android.support.design.widget.FloatingActionButton
android:id="@+id/actionbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_gravity="end"
android:visibility="gone" />

And here is my oncreate method on activity associated with the above layout:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    tabletSize = getResources().getBoolean(R.bool.isTablet);
    if (!tabletSize) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }
    setContentView(R.layout.order_details);

    ab = getSupportActionBar();
    ab.setDisplayUseLogoEnabled(true);
    ab.setDisplayHomeAsUpEnabled(true);

    actionButton = (FloatingActionButton) findViewById(R.id.actionbutton);
    actionButton.setBackgroundColor(getResources().getColor(R.color.actionbar));
    actionButton.setImageResource(R.drawable.ic_action_send);

    appPreference = new AppPreference(this);
    mRecyclerView = (RecyclerView) findViewById(R.id.prodct_list);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());

    mLayoutManager = new LinearLayoutManager(this);
    mRecyclerView.setLayoutManager(mLayoutManager);

    final Intent intent = getIntent();
    pyid = intent.getExtras().getLong(Quotes.ID);

    mItemsDetail = QuoteItems.getItemsArray(this ,pyid);

    mAdapter = new DeliveryDetailsAdapter(this, mItemsDetail);
    mRecyclerView.setAdapter(mAdapter);

    pContent = new ParseContent(this);
    title = intent.getExtras().getString(Quotes.REFERENCE);
    if (pyid == 0)
        finish();

    if (Validating.areSet(title))
        ab.setTitle("Quote Details");
    else
        ab.setTitle(getString(R.string.strorder));

    mRecyclerView.addOnItemTouchListener(
            new RecylerItemClick(this, new RecylerItemClick.OnItemClickListener() {
                @Override
                public void onItemClick(View view, int position) {

                }
            })
    );

And here is my list of items populated on recyclerview:

<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/card_view11"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/rltotals"
    android:layout_below="@+id/autotxtsaleclientname"
    card_view:cardBackgroundColor="@color/white"
    card_view:cardCornerRadius="7.0dip"
    card_view:cardElevation="0dp">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/prodct_list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:scrollbars="vertical" />
</android.support.v7.widget.CardView>

And when i run the application on that part the items on recyclerview displays with large gap between each item Can anyone help me to solve the issue with the gap between the items

2 Answers2

1

The problem is with your adapter class. You need to make the adapter class parent height as wrap_content. Since your recylerview is vertical, you need to change the height of the adapter parent layout to wrap_content. After that also if the problem exists check whether any other adapter child view height is match_parent, if so change that to wrap_content.

Hope this is Helpful :)

Jeevanandhan
  • 1,073
  • 10
  • 18
0

check the item layout inside DeliveryDetailsAdapter for inflating each item (OncreateViewholder)

You may have given some margin in root layout. remove margin from root layout and set width as match parent and height as wrap_content

Victor
  • 4,171
  • 1
  • 29
  • 37