Android: Last Line of Textview Cut Off

Android: Last line of textview cut off

I've encountered the same cut-off issue as shown at the screenshot. It is caused by the baseline alignment in the horizontal LinearLayout. TextView and Spinner have different baselines due to font size difference. To fix the issue it is needed to disable baseline alignment for the layout by setting:

android:baselineAligned="false"

or in the code:

layout.setBaselineAligned(false);

android, last line of textview inside of scrollview slightly cutoff

For your TextView which is inside ScrollView , add android:paddingBottom="10dip"
It will work perfectly. You give any value for padding.

Android Textview text cut off at bottom

One of your LinearLayouts has height set to fill_parent. change it to wrap_content.

Also, remove the min_height attribute. Yout have two text fields in there, so it looks like you're totally OK with the second getting cut off.

It's kind of hard to tell what you're going for, but see if that helps.

Why is the text in the text view cut off in the recycler view?

Why did you created a linear layout inside a constraint layout?

You can remove linear layout an put your ImageView and TextView directly inside constraint layout and constraint TextView top to bottom of ImageView

and instead of using weight you can use layout_constraintHeight_percent just like below:

app:layout_constraintHeight_percent="0.2"

But I recommend you not to use height_percant or weight and also avoid sizing the views width/height statically. it can cause problems on different screens

I think its better to remove LinearLayout and also remove weight and add this line to your ImageView:

app:layout_constraintDimensionRatio="H,5:4"

Write your TextView and ImageView like below:

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:background="@drawable/thumbnail_frame"
android:paddingLeft="16dp"
android:paddingTop="12dp"
android:paddingRight="16dp"
android:paddingBottom="12dp">

<ImageView
android:id="@+id/thumbnail_item"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/dark_red"
android:scaleType="centerCrop"
app:layout_constraintDimensionRatio="H,5:4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/thumbnail_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:padding="8dp"
android:text="@string/title_place_holder"
android:textColor="@color/white"
android:textSize="12sp"
app:layout_constraintTop_toBottomOf="@id/thumbnail_item"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

TextView populated dynamically cutting off last line of text

I boiled the layout down to its base parts. Here's the stripped down version, that's still cutting the text off:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/flag"
>

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

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#4f4f4f"
android:id="@+id/contentTextView"/>

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/button_blue_rascal_button"
android:id="@+id/buttonMoreInfo"/>

</LinearLayout>

</LinearLayout>

The problem, I think, is that the parent LinearLayout is getting its width from the ImageView inside it. Somewhere in this mix, the TextView is getting an incorrect value for its requested height. I would imagine this has to do with how the UI is calculated. The parent must ask the children for their requested width, then go back and tell everybody what their width is, then ask for heights. Something like that. Anyway, the following works. The image width is 263 pixels (in mdpi), so if I set 263dp instead of wrap_content on the parent layout, everything is OK.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/flag"
>

<LinearLayout
android:layout_width="263dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical">

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#4f4f4f"
android:id="@+id/contentTextView"/>

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/button_blue_rascal_button"
android:id="@+id/buttonMoreInfo"/>

</LinearLayout>

</LinearLayout>

Setting the TextView to wrap_content works too, although it then pushes the whole layout larger than I want it to be.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/flag"
>

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

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#4f4f4f"
android:id="@+id/contentTextView"/>

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/button_blue_rascal_button"
android:id="@+id/buttonMoreInfo"/>

</LinearLayout>

</LinearLayout>

Not sure what the takeaway here is. Summary, if you start seeing calculated height issues, consider fixing a width in there for the parent, just so the UI calculations don't get confused.



Related Topics



Leave a reply



Submit