Nanda Z
Nanda Z

Reputation: 1876

How to remove gap on my adapter row layout

I have a layout row that is used on adapter like the following:

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        android:orientation="vertical">

        <TextView
            android:id="@+id/title_related"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Ini Judul Related" />

        <TextView
            android:id="@+id/time_related"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="0dp"
            android:text="Jumat, 21 Desember 2018 04:45"
            android:textStyle="bold" />
    </LinearLayout>

    <ImageView
        android:id="@+id/image_related"
        android:layout_width="350dp"
        android:layout_height="200dp"
        android:layout_weight="2"
        android:paddingEnd="10dp"
        android:src="@drawable/picture"
        tools:ignore="RtlSymmetry" />

</LinearLayout>

My problem is, there is always a gap that separates between the large enough layouts. Even though I have removed all the padding, like the left and right padding. Is there something I don't see? In addition, the display is looked like this: row layout with big gap
You can copy this layout code snippet and paste it to your test layout to see the problem.

Upvotes: 1

Views: 64

Answers (3)

SREE
SREE

Reputation: 464

Make the ImageView like below code. This will keep the width as you required.

<ImageView
    android:id="@+id/image_related"
    android:layout_width="350dp"
    android:layout_height="wrap_content"
    android:scaleType="fitCenter"
    android:paddingEnd="10dp"
    android:src="@drawable/picture"
    tools:ignore="RtlSymmetry" />

Upvotes: 1

Jayesh Bakhshi
Jayesh Bakhshi

Reputation: 11

There is a 10dp padding at the end of imageview. Also try using min(/max)height and min(/max)width instead of absolute value.

And you can always scale your image ,set scaletype to fitXY

Upvotes: 1

Sagar
Sagar

Reputation: 24907

The problem is your ImageView. You have set android:layout_height="200dp" which will enforce the view to Height to be at least 200dp regardless of the actual size of the image. Since your Parent layout is android:layout_height="wrap_content" you will get above behavior.

One way to solve this is to set the android:layout_height="wrap_content" inside ImageView. The drawback of this approach is, you lose control over the height of ImageView. If the actual image height is like 300dp then the view will be huge.

Another way is to reduce the height of ImageView. Do it only if you want to enforce specific height to all the images.

Upvotes: 2

Related Questions