Search code examples
androidxmlandroid-layout

Remove gap between 2 textviews in a constraint layout


I have the following simple layout

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/favouriteStore"
    android:layout_width="@dimen/favourite_store_card_width"
    android:layout_height="@dimen/favourite_store_card_height">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:id="@+id/layoutContent"
        android:layout_height="match_parent"
        android:background="@drawable/background_with_gradiant2"
        android:translationZ="10dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <com.google.android.material.imageview.ShapeableImageView
            android:id="@+id/imageViewStoreLogo"
            android:layout_width="@dimen/margin_60dp"
            android:layout_height="@dimen/margin_60dp"
            android:layout_marginEnd="@dimen/margin_16dp"
            android:layout_marginBottom="@dimen/margin_16dp"
            android:visibility="visible"
            android:scaleType="fitXY"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:shapeAppearanceOverlay="@style/roundedImageView" />

        <androidx.appcompat.widget.AppCompatTextView
            android:id="@+id/textViewStoreTitle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginEnd="@dimen/margin_20dp"
            android:textColor="@color/white"
            android:textSize="@dimen/text_medium"
            app:lineHeight="19.2dp"
            android:lineSpacingExtra="-2sp"
            android:lines="1"
            android:ellipsize="end"
            android:includeFontPadding="false"
            app:fontFamily="@font/graphikthai_semibold_app"
            app:layout_constraintVertical_bias="0"
            app:layout_constraintBottom_toTopOf="@id/textViewStoreSubTitle"
            app:layout_constraintEnd_toStartOf="@+id/imageViewStoreLogo"
            app:layout_constraintStart_toStartOf="@+id/textViewStoreSubTitle"
            android:layout_marginBottom="@dimen/margin_5dp"
            tools:text="Robinson" />

        <androidx.appcompat.widget.AppCompatTextView
            android:id="@+id/textViewStoreSubTitle"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/margin_16dp"
            android:layout_marginEnd="@dimen/margin_20dp"
            android:layout_marginBottom="16dp"
            android:ellipsize="end"
            android:includeFontPadding="false"
            android:letterSpacing="0"
            android:lineSpacingExtra="3sp"
            android:lines="1"
            android:textColor="@color/white"
            android:textSize="@dimen/sp13"
            app:fontFamily="@font/cpn_regular"
            app:layout_constraintVertical_bias="0"
            app:layout_constraintEnd_toStartOf="@+id/imageViewStoreLogo"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"

            app:lineHeight="16dp"
            tools:text="Bringing you the best" />
    </androidx.constraintlayout.widget.ConstraintLayout>

    <androidx.appcompat.widget.AppCompatImageView
        android:id="@+id/imageViewStore"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clickable="true"
        android:focusable="true"
        android:scaleType="fitXY"
        android:transitionGroup="true"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/bg_banner_image_placeholder" />

</androidx.constraintlayout.widget.ConstraintLayout>

Which looks like this, and the green line there is a gap of 5dp that I want to remove:

enter image description here

However, I want remove the gap between the 2 text views.

The green box there is a 5dp gap that I want to remove. Where does this come from?

enter image description here


Solution

  • In your AppCompatTextView textViewStoreTitle, remove the layout_marginBottom and you should be okay.

    android:layout_marginBottom="@dimen/margin_5dp"