0

i need to add two text views to a linear layout, the problem is that sometimes, depending on font size, an strange spacing appears in the middle, and i don't want it there.

Here is a screenshot: Text views in linear layout

You can see that the first and second textview are perfectly aligned, but the second and third are not.

Why is this happening?

Here's the test xml:

<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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        tools:layout_editor_absoluteX="1dp"
        tools:layout_editor_absoluteY="1dp">

        <TextView
            android:id="@+id/textView8"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textSize="24sp" />

        <TextView
            android:id="@+id/textView9"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textSize="24sp" />

        <TextView
            android:id="@+id/textView10"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textSize="24sp" />

        <TextView
            android:id="@+id/textView11"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textSize="24sp" />

        <TextView
            android:id="@+id/textView12"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textSize="24sp" />

    </LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

Edit: Suggested question seems to refer to the same problem, however the proposed solutions don't fix my problem.

Gammel
  • 43
  • 5
  • Does this answer your question? [Android: TextView: Remove spacing and padding on top and bottom](https://stackoverflow.com/questions/4768738/android-textview-remove-spacing-and-padding-on-top-and-bottom) – Tamir Abutbul Jul 22 '20 at 05:22

1 Answers1

0

Add in your textView . It will removed extra padding

android:includeFontPadding="false"

Try this:

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    

        <TextView
            android:id="@+id/textView8"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            android:text="TextView"
            android:textSize="24sp" />

        <TextView
            android:id="@+id/textView9"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TextView"
            app:layout_constraintTop_toBottomOf="@id/textView8"
            app:layout_constraintStart_toStartOf="parent"
            android:includeFontPadding="false"
            android:textSize="24sp" />

        <TextView
            android:id="@+id/textView10"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintTop_toBottomOf="@id/textView9"
            app:layout_constraintStart_toStartOf="parent"
            android:text="TextView"
            android:textSize="24sp" />

</androidx.constraintlayout.widget.ConstraintLayout>
chand mohd
  • 2,363
  • 1
  • 14
  • 27