0

I'm currently working on making my app display better on different screen sizes. This TextView should now extend to the end of the View. This works, but the problem is that it then shows this ugly half line. I already set other margins and paddings but this made it look bad on one device or another, so I was asking myself whether there is a good solution to make it look right everywhere. This is the TextView corresponding:

<TextView
    android:id="@+id/text3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/relative_layout"
    android:layout_marginBottom="5dp"
    android:layout_marginTop="5dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="5dp"
    android:maxLines="100"
    android:ellipsize="end"
    android:textSize="18sp"
    android:clickable="true"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textIsSelectable="false"/>

This is the way it currently looks

It would be great if someone was able to help me, thanks in advance!

Made by FA
  • 710
  • 2
  • 7
  • 27

1 Answers1

0

I created an AdaptingTextView like this:

public class AdaptingTextView extends TextView {

public AdaptingTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

public AdaptingTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}

public AdaptingTextView(Context context) {
super(context);
}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);

// set fitting lines to prevent cut text
int fittingLines = h / this.getLineHeight();
if (fittingLines > 0) {
    this.setLines(fittingLines);
}
}
}

Source: https://stackoverflow.com/a/26998769/3272495

Community
  • 1
  • 1
Made by FA
  • 710
  • 2
  • 7
  • 27