-1

Good day. Not a problem to align the text inside the TextView horizontally. But how can I press the text inside the TextView to the top? It is necessary to align the text to the top in two TextViews located near and with different text sizes inside.

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="60sp"
        android:gravity="top"
        android:text="TextView"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:text="TextView"
        app:layout_constraintStart_toEndOf="@+id/textView2"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

here the image

Addition: android:includeFontPadding="false" does not solve the problem:

that's why

Allan Stark
  • 11
  • 1
  • 5

1 Answers1

3

include that in your textviews:

android:includeFontPadding="false"
Nikos Hidalgo
  • 3,666
  • 9
  • 25
  • 39
  • 1
    I apologize, but it seems that this does not solve the problem - the small distance between the top of the text and the upper border of the container still remains. And this distance is proportional to the size of the text inside the container, so the gap for my two containers with different sizes of text inside will also be different. – Allan Stark Dec 20 '18 at 09:18
  • I wouldn't necessarily recommend it, but try adding a negative marginTop for the view and see what happens – Nikos Hidalgo Dec 20 '18 at 09:31