Android - Remove White Space Between Recyclerview Items

Asked

Viewed 500 times

1

I have a problem just like this here. I’m using the 'com.android.support:recyclerview-v7:28.0.0'. The XML is as follows, activity_main.xml, problem lies in the recyclerOverlay:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/mRootLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <Button
            android:id="@+id/btnheader"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#ffffff"
            android:text="Convite Virtual"
            android:textAllCaps="false"
            android:textSize="25dp"
            android:visibility="visible" />

    </RelativeLayout>

    <FrameLayout
        android:id="@+id/mainFrame"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <FrameLayout
            android:id="@+id/frame"
            android:layout_width="380dp"
            android:layout_height="500dp"
            android:layout_gravity="top|center_horizontal"
            android:background="#ffffffff">

            <FrameLayout
                android:id="@+id/framecontainer"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <ImageView
                    android:id="@+id/bgImage"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="fitXY"

                    android:visibility="gone" />


                <com.selfcoderlab.birthday.photoframe.custom.TouchImageView
                    android:id="@+id/imgSize"


                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center"

                    android:scaleType="centerCrop" />

                <RelativeLayout
                    android:id="@+id/frameContainer"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical">

                        <FrameLayout
                            android:id="@+id/rr_1"
                            android:layout_width="match_parent"
                            android:layout_height="30dip"
                            android:layout_weight="0.5">

                            <ImageView
                                android:id="@+id/iv_1"
                                android:layout_width="fill_parent"
                                android:layout_height="match_parent"
                                android:scaleType="matrix" />

                            <ImageView
                                android:id="@+id/imgOverlayView"
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:scaleType="fitXY"
                                android:layout_gravity="center_horizontal|top" />

                        </FrameLayout>

                    </LinearLayout>

                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_toLeftOf="@+id/main_img"
                        android:background="#ffffff">

                    </RelativeLayout>

                    <RelativeLayout

                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_above="@+id/main_img"
                        android:background="#ffffff">

                    </RelativeLayout>

                    <ImageView
                        android:id="@+id/main_img"
                        android:layout_width="380dp"
                        android:layout_height="500dp"
                        android:layout_centerHorizontal="true"
                        android:layout_centerVertical="true"
                        android:scaleType="fitXY"
                         />

                    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_below="@+id/main_img"
                        android:background="#ffffff" />

                    <RelativeLayout
                        android:layout_width="match_parent"

                        android:layout_height="match_parent"
                        android:layout_toRightOf="@+id/main_img"
                        android:background="#ffffff">

                    </RelativeLayout>
                </RelativeLayout>


                <com.selfcoderlab.birthday.photoframe.custom.StickerBtn
                    android:id="@+id/sticker_view"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:visibility="gone" />

            </FrameLayout>


        </FrameLayout>


        <GridView
            android:id="@+id/gridView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#80000000"
            android:gravity="center"
            android:horizontalSpacing="2dp"
            android:numColumns="@integer/grid_columns"
            android:padding="4dp"
            android:stretchMode="columnWidth"
            android:verticalSpacing="2dp"
            android:visibility="gone" />

        <SeekBar
            android:id="@+id/seekOverlay"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:layout_marginBottom="50dp"
            android:padding="16dp" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerOverlay"
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:layout_gravity="bottom"
            android:background="#444"
            />

    </FrameLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:orientation="vertical">


        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:background="#444"
            android:visibility="gone" />

        <LinearLayout

            android:layout_width="match_parent"

            android:layout_height="wrap_content"
            android:background="#283037"
            android:orientation="horizontal">

            <LinearLayout

                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center">

                <ImageView
                    android:id="@+id/imgFrame"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:clickable="true"
                    android:src="@drawable/selector_frame" />
            </LinearLayout>

            <LinearLayout

                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center">

                <ImageView
                    android:id="@+id/imgGallery"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:clickable="true"
                    android:src="@drawable/selector_gallery" />
            </LinearLayout>


            <LinearLayout

                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center">

                <ImageView
                    android:id="@+id/imgOverlay"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:clickable="true"
                    android:src="@drawable/selector_overlay" />
            </LinearLayout>


            <LinearLayout

                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center">

                <ImageView
                    android:id="@+id/imgSticker"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:clickable="true"
                    android:src="@drawable/selector_sticker" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center">

                <ImageView
                    android:id="@+id/imgText"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:clickable="true"
                    android:src="@drawable/selector_text" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center">

                <ImageView
                    android:id="@+id/imgSave"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:clickable="true"
                    android:src="@drawable/selector_save" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center">

                <ImageView
                    android:id="@+id/imgShare"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:clickable="true"
                    android:src="@drawable/selector_share" />
            </LinearLayout>

        </LinearLayout>


    </LinearLayout>


</LinearLayout>

sticker_category_item_view.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">


    <ImageView
        android:padding="2dp"
        android:layout_gravity="center"
        android:id="@+id/imgSticker"
        android:layout_width="48dp"
        android:layout_height="48dp" />
</LinearLayout>

Mainactivity.java:

mAdapter = new StickersAdapter(stickerArrayList);
LinearLayoutManager layoutManager = new LinearLayoutManager(
        MainActivity.this, LinearLayoutManager.HORIZONTAL, false);
recyclerOverlay.setLayoutManager(layoutManager);
recyclerOverlay.setAdapter(mAdapter);

public class StickersAdapter extends RecyclerView.Adapter<StickersAdapter.MyViewHolder> {

        private List<Sticker> StickersList;

        public class MyViewHolder extends RecyclerView.ViewHolder {
            public ImageView imgSticker;

            public MyViewHolder(View view) {
                super(view);
                imgSticker = (ImageView) view.findViewById(R.id.imgSticker);

            }
        }


        public StickersAdapter(List<Sticker> StickersList) {
            this.StickersList = StickersList;
        }

        @Override
        public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            View itemView = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.sticker_category_item_view, parent, false);

            return new MyViewHolder(itemView);
        }

        @Override
        public void onBindViewHolder(MyViewHolder holder, final int position) {
            Sticker = StickersList.get(position);

            Glide.with(MainActivity.this).load(Sticker.stickerId).into(holder.imgSticker);
//            holder.imgSticker.setText(Sticker.getTitle());
            holder.imgSticker.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Sticker = StickersList.get(position);
                    imgOverlayView.setVisibility(View.VISIBLE);
                    Glide.with(MainActivity.this).load(Sticker.stickerId).into(imgOverlayView);
                    initShapeAlphaEffect();
                }
            });
        }

        @Override
        public int getItemCount() {
            return StickersList.size();
        }
    }

OBS: in the old versions the blank space does not appear. Even using wrap_content the whitespace continues in version 28.0.0. Can anyone help me with this issue?

  • Add the Recycleview line XML to your question, please

  • How’s your Recycleview Item? By changing it we might be able to hit maybe there is space between the intenses inside your Recycleview .

  • It is inside a Framelayout that is inside a Linearlayout.

  • 1

    Ask a small example with code that replicates the situation and can easily be used to test.

  • 1

    @Stéfano click on the edit below your question and add the full XML where Recycleview and the XML code of the Recycleview item are from so we can analyze and help you.

  • I solved the problem by editing the Recycleview item. Thanks for all your help.

Show 1 more comment

3 answers

1

Try to put recyclerView inside a Coordinatorlayout like this:

<android.support.design.widget.CoordinatorLayout
    android:layout_width="wrap_content"
    android:layout_height="50dp">

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

</android.support.design.widget.CoordinatorLayout>
  • Thanks for the answer. I tried Coordinatorlayout in several ways, but without success, the problem persists.

0


The problem was solved by changing the layout of the sticker_category_item_view.xml, using only wrap_content, thus:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <ImageView
        android:padding="2dp"
        android:layout_gravity="center"
        android:id="@+id/imgSticker"
        android:layout_width="48dp"
        android:layout_height="48dp" />
</LinearLayout>

-1

Adjust your Recycler to grab available screen space.

    <android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerOverlay"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#444" />

Check the model item you pass in the Adapter, there in the Inflater, because it should be with the following configurations of tamnaho and height:

    android:layout_width="match_parent"
    android:layout_height="wrap_content"
  • I checked, but still unsuccessful.

  • I could remove the Linearlayoutmanager.HORIZONTAL, or put it as VERTICAL?

  • I’ve tried that, he gets the same problem in vertical mode.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.