Java Nerd
Java Nerd

Reputation: 968

Remove Strange Space between RecyclerView Items

I am newbie to android development and learning it to my own. I have a very strange problem of having strange space that comes in between every item of my recycler view. I have the following:

My recycler view is vertical with grid view layout of 2 spans(columns). What I have been trying is:


Code for Layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_marginLeft="@dimen/size_five"
              android:layout_marginRight="@dimen/size_five"
              android:layout_marginTop="@dimen/size_fifteen"
              android:background="@color/blackColor"
              android:clickable="true"
              android:focusable="true"
              android:orientation="vertical">

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="50">

            <ImageView
                android:id="@+id/album_image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@color/blackColor"
                />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/lowerline"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="15"
            android:background="@color/hotpinkColor"
            android:orientation="horizontal">

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="4"
                android:orientation="horizontal">

                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="@dimen/size_ten">

                    <TextView
                        android:id="@+id/album_title_text"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerVertical="true"
                        android:gravity="left"
                        android:text="Album Title"
                        android:textColor="@color/whiteColor"
                        android:textSize="@dimen/size_eight"
                        android:textStyle="bold"/>
                </RelativeLayout>
            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_marginRight="@dimen/size_ten"
                android:layout_weight="5"
                android:orientation="horizontal">

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

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

                        <ImageView
                            android:id="@+id/downloader"
                            android:layout_width="@dimen/size_thirty_six"
                            android:layout_height="@dimen/size_thirty_six"
                            android:layout_centerInParent="true"
                            android:src="@drawable/donwloaderimager"/>
                    </RelativeLayout>
                </LinearLayout>

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

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

                        <ImageView
                            android:id="@+id/setteraswall"
                            android:layout_width="@dimen/size_fourty"
                            android:layout_height="@dimen/size_fourty"
                            android:layout_centerInParent="true"
                            android:src="@drawable/setteras"/>
                    </RelativeLayout>
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>

    </LinearLayout>

</LinearLayout>

Screen Shot enter image description here

The Black space is showing the extra strange space that I want to remove.

Upvotes: 1

Views: 2011

Answers (1)

kgandroid
kgandroid

Reputation: 5595

Change:

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="50">

            <ImageView
                android:id="@+id/album_image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@color/blackColor"
                />
        </LinearLayout>

to

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="50">

            <ImageView
                android:id="@+id/album_image"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@color/blackColor"
                />
        </LinearLayout>

That is change the height of the second parent linear layout to wrap_content

Upvotes: 1

Related Questions