Android: Last line of textview cut off
Asked Answered
C

21

122

I have a horizontal LinearLayout containing a TextView followed by a Spinner next to it. This LinearLayout is dynamically inflated multiple times in a fixed vertical LinearLayout contained within a RelativeLayout.

The problem is that since I switched from Theme.light to Theme.holo.light, the last line of the TextView gets cut in half. This happens when the dynamic text is long and spans more than one row.

enter image description here

I have been able to fix this by adding bottom padding to the horizontal LinearLayout containing the TextView and Spinner.

This does not feel like a fix, but more of a hack. Can someone please give me some advice on how to properly fix this?

I have also read some other questions, but none seem to help.

Horizontal Linear layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:layout_marginRight="20dp"
        android:text="TextView"/>

    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</LinearLayout>

Relative layout where above layout is dynamically inflated at Linear Layout with id ll2_7:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/relLayoutButtonNext"
        android:layout_below="@id/textView1" >

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="20dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:paddingTop="10dp" >

            <TextView
                android:id="@+id/textView10"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingRight="30dp"
                android:text="2.7" />

            <TextView
                android:id="@+id/textView11"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="10dp"
                android:layout_toRightOf="@id/textView10"
                android:text="@string/question2_7" />


            <LinearLayout
                android:id="@+id/ll2_7"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/textView11"
                android:layout_below="@+id/textView11"
                android:orientation="vertical" android:layout_marginBottom="20dp">
            </LinearLayout>

        </RelativeLayout>

    </ScrollView>

</RelativeLayout>

EDIT: Here is the complete layout xml for above:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/textView1"
        style="@style/question_section_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:text="@string/question2_header" />

    <RelativeLayout
        android:id="@+id/relLayoutButtonNext"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@color/bottomBar"
        android:paddingBottom="3dp"
        android:paddingLeft="50dp"
        android:paddingRight="50dp"
        android:paddingTop="3dp" >

        <Button
            android:id="@+id/buttonNext"
            android:layout_width="180dp"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:onClick="nextStep"
            android:text="Next Section"
            android:textSize="20sp" />

        <Button
            android:id="@+id/buttonPrevious"
            android:layout_width="180dp"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:onClick="previousStep"
            android:text="Previous Section"
            android:textSize="20sp" />
    </RelativeLayout>


    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/relLayoutButtonNext"
        android:layout_below="@id/textView1" >



        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="20dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:paddingTop="10dp" >

            <TextView
                android:id="@+id/textView10"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingRight="30dp"
                android:text="2.7" />

            <TextView
                android:id="@+id/textView11"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginBottom="10dp"
                android:layout_toRightOf="@id/textView10"
                android:text="@string/question2_7" />


            <LinearLayout
                android:id="@+id/ll2_7"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/textView11"
                android:layout_below="@+id/textView11"
                android:orientation="vertical" android:layout_marginBottom="20dp">

            </LinearLayout>

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/textView10"
                android:layout_below="@+id/ll2_7"
                android:text="2.8" />

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/ll2_7"
                android:layout_toRightOf="@+id/textView10"
                android:text="@string/question2_8" android:layout_marginBottom="10dp"/>


            <LinearLayout
                android:id="@+id/ll2_8"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/textView3"
                android:layout_below="@+id/textView3"
                android:layout_marginBottom="20dp"
                android:orientation="vertical" >

            </LinearLayout>

            <TextView
                android:id="@+id/textView4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/textView2"
                android:layout_below="@+id/ll2_8"
                android:text="2.9" />

            <TextView
                android:id="@+id/textView5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/ll2_8"
                android:layout_toRightOf="@+id/textView10"
                android:text="@string/question2_9" android:layout_marginBottom="10dp"/>


            <LinearLayout
                android:id="@+id/ll2_9"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/textView5"
                android:layout_toRightOf="@+id/textView10"
                android:orientation="vertical" android:layout_marginBottom="20dp">

            </LinearLayout>

            <TextView
                android:id="@+id/textView6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/textView4"
                android:layout_below="@+id/ll2_9"
                android:text="2.10" />

            <TextView
                android:id="@+id/textView7"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/ll2_9"
                android:layout_toRightOf="@+id/textView10"
                android:text="@string/question2_10" android:layout_marginBottom="10dp"/>


            <LinearLayout
                android:id="@+id/ll2_10"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/textView7"
                android:layout_marginBottom="20dp"
                android:layout_toRightOf="@+id/textView10"
                android:orientation="vertical" >

            </LinearLayout>

            <TextView
                android:id="@+id/textView8"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/textView6"
                android:layout_below="@+id/ll2_10"
                android:text="2.11" />

            <TextView
                android:id="@+id/textView9"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/ll2_10"
                android:layout_toRightOf="@+id/textView10"
                android:text="@string/quesiton2_11" android:layout_marginBottom="10dp"/>


            <LinearLayout
                android:id="@+id/ll2_11"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/textView9"
                android:layout_below="@+id/textView9"
                android:orientation="vertical" android:layout_marginBottom="20dp">

            </LinearLayout>

            <TextView
                android:id="@+id/textView12"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/textView8"
                android:layout_below="@+id/ll2_11"
                android:text="2.11.1" />

            <TextView
                android:id="@+id/textView13"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/ll2_11"
                android:layout_toRightOf="@+id/textView10"
                android:text="@string/question2_11_1" android:layout_marginBottom="10dp"/>


            <LinearLayout
                android:id="@+id/ll2_11_1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/textView13"
                android:layout_toRightOf="@+id/textView10"
                android:orientation="vertical" android:layout_marginBottom="20dp">

            </LinearLayout>

        </RelativeLayout>

    </ScrollView>

</RelativeLayout>
Cleo answered 28/6, 2012 at 11:42 Comment(3)
try with removing android:paddingBottom="20dp"Polysemy
Try padding over the textview and linear layout margins may also give a nice handCephalothorax
LinearLayout is really problematic when used horizontally. Instead use the ConstraintLayout. See. https://mcmap.net/q/182458/-how-to-add-different-weight-to-constraintlayout-viewsInterweave
C
68

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);
Cent answered 25/6, 2014 at 10:36 Comment(6)
I wish I could up-vote this 100 times! I've wasted sooooo much time in the past few days on this issue, and your answer was my solution! I didn't realize what was going on for so long because it is so hard to debug the view hierarchy on Android. Thanks so much!!!Quincyquindecagon
This was the solution to my issue, in addition to Rynardt's answer. Thank you!Georgeanngeorgeanna
This is the correct answer and it point out the reason why error happened. Thanks.Osmen
This is huge tip for situations like this. Not bad at all. Thank you!Sanatorium
Thank you so much. So, this is actually a bug, right?Regulation
Angga Arya S, No it is not a bug. Just the layout's default alignment setting leads to confusion in case if element text sizes are different and there is a multi-line text.Cent
C
271

I applied a LayoutGravity to the TextView item:

android:layout_gravity="fill"
Cleo answered 28/6, 2012 at 13:56 Comment(7)
perfect, tnx, +1; note that many layout_gravity values helps, eg. center_verticalTyratyrannical
Where this doesn't work, adding a padding value of "1sp" should work. I create a style extending @android:style/Widget.TextView and add the following lines: <item name="android:gravity">fill</item> <item name="android:padding">1sp</item>Sandoval
why this problem happens just with arabic text ?!Collagen
The answer here alone didn't work for me at first because my TextView, which was wrapped in a LinearLayout with a checkbox and a few other things, had the height of fill_parent instead of wrap_content. Changing just the height to wrap_content didn't work for me, I had to also use this solution. Nice work!Corn
That's just a workaround. The proper solution is to add android:baselineAligned="false" to your LinearLayoutSinapism
Although this seems to work, the correct solution is the one from tomrozb's comment above, or Jusid's answerReally
It's 2017, a multi-line TextView may still get clipped with wrap_content, and your answer still works. Thanks!Octoroon
C
68

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);
Cent answered 25/6, 2014 at 10:36 Comment(6)
I wish I could up-vote this 100 times! I've wasted sooooo much time in the past few days on this issue, and your answer was my solution! I didn't realize what was going on for so long because it is so hard to debug the view hierarchy on Android. Thanks so much!!!Quincyquindecagon
This was the solution to my issue, in addition to Rynardt's answer. Thank you!Georgeanngeorgeanna
This is the correct answer and it point out the reason why error happened. Thanks.Osmen
This is huge tip for situations like this. Not bad at all. Thank you!Sanatorium
Thank you so much. So, this is actually a bug, right?Regulation
Angga Arya S, No it is not a bug. Just the layout's default alignment setting leads to confusion in case if element text sizes are different and there is a multi-line text.Cent
B
34

I had the same problem, and found that simply adding

android:includeFontPadding="false"

the final line of text no longer had its descenders clipped.

Brunell answered 27/5, 2015 at 17:56 Comment(1)
With custom fonts, this might be the perfect fix. This is the only solution that worked for me when using Droid Sans Japanese.Conformity
D
12

I added some dummy space after text by adding

textView.setText(firstString+"\n");

I tried all other solution.But this was the only solution worked for me

Daydream answered 22/10, 2014 at 9:33 Comment(2)
this what you call "chepi"Johnsten
This was the only solution that worked for me, all others didnt do anything. Thanks!Turbulence
T
7

I found a different solution by extending TextView and adding a custom Class 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);
        }
    }

}
Transmutation answered 18/11, 2014 at 16:10 Comment(3)
Works great but be careful if you have layout_margin specified on the textview as it can alter the number of fitting lines to be shorter than it should be! I switched to using padding instead of margins and problem fixedBrom
This works absolutely perfect. By far the best solution i've found.Rickard
This is the correct answer, thanks! To make it a bit nicer and add '...' to the end of the text before it is truncated add this.setEllipsize(TextUtils.TruncateAt.END); in the if statement above, and remove android:ellipsize="end" from the XML which for some reason breaks it.Echoechoic
S
6

Put the problematic textview inside a framelayout. I think the text view is not calculated correctly because of the sibling view, Spinner.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <FrameLayout
        android:layout_width="150dp"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/textView1"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="20dp"
            android:text="TextView"/>
    </FrameLayout>
    <Spinner
        android:id="@+id/spinner1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
</LinearLayout>
Squarely answered 28/8, 2017 at 17:53 Comment(2)
I had CheckBox in same LinearLayout. This solved the issue.Glider
Worked like a charm with a CheckBox situation like @ChintanShahKilohertz
S
5

When this occurs, you should ensure that the TextView is not growing larger than it's container -

If a TextView is set to wrap_content and it's container (or an ancestor container) doesn't leave room for the TextView to grow into it can be occluded.

If that's not the case, it's also possible the onMeasure() of the TextView sometimes doesn't correctly measure the tails of letters, non-latin characters or the effects from text being italic. You can correct for this by setting a global style for your TextView so it will be picked up without needed to change your entire code base:

Ensure that you're application/activities use a custom theme like so:

<style name="Custom" parent="@android:style/Theme.Light">   
    <item name="android:textViewStyle">@style/Custom.Widget.TextView</item>
</style>

<style name="Custom.Widget.TextView" parent="@android:style/Widget.TextView"> 
    <item name="android:gravity">fill</item>
    <item name="android:padding">1sp</item>
</style>

The answer by @Rynadt was really helpful in getting to the above stage. Setting the gravity of the Text inside the View ensures on some devices that occlusion never takes place (The text is correctly fitted inside the view), on others a helping hand with padding of an sp value, ensures that the tails et al are accounted for with a TextSize specific value.

Sandoval answered 4/12, 2013 at 11:39 Comment(0)
M
5

My solution was close to the accepted one, but I had to change it to

   android:layout_gravity="fill_vertical"

instead. Otherwise the other rows would have been stretch as well with added line breaks at random places. For example, the biggest row had 4 lines, so another row was changed from

this is a testphrase

to

thi
s is
a testph
rase
Meanly answered 11/2, 2016 at 7:56 Comment(0)
P
4

try with removing android:paddingBottom="20dp"

from

 <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="20dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:paddingTop="10dp" >
Polysemy answered 28/6, 2012 at 11:49 Comment(1)
The padding there is actually not related as there are additional items contained within this relative layout with the padding. I removed them for easier reading of this post. See edit in question.Cleo
S
4

getViewTreeObserver().addOnGlobalLayoutListener does not work in a recycler view. If you're using a recycler, use View.addOnLayoutChangeListener:

I found that the ellipsizing I defined for textView in xml was not always reflected so I programmatically set it before reassigning the text property. This worked for me.

textView.addOnLayoutChangeListener(new OnLayoutChangeListener() {
    @Override
        public void onLayoutChange(View v, int left, int top, int right, int bottom,
                                   int oldLeft, int oldTop, int oldRight, int oldBottom) {
            textView.removeOnLayoutChangeListener(this);
            float lineHeight = textView.getLineHeight();
            int maxLines = (int) (textView.getHeight() / lineHeight);
            if (textView.getLineCount() != maxLines) {
                textView.setLines(maxLines);
                textView.setEllipsize(TextUtils.TruncateAt.END);
                // Re-assign text to ensure ellipsize is performed correctly.
                textView.setText(model.getText());
            }
        }
    });
Statics answered 19/5, 2017 at 12:9 Comment(0)
I
3

If you have this problem and your TextView is inside a RelativeLayout, try switching the RelativeLayout for a LinearLayout.

That fixed the problem for me

Inwrap answered 8/11, 2012 at 12:22 Comment(2)
This is the only solution which works for me (strange behavior) ! ThxIgneous
How can you simply "switch" from RelativeLayout to LinearLayout? If you have to layout relatively it's nearly impossible to implement with LinearLayout.Bowery
S
3

You can use a global layout listener for a TextView in any type of ViewGroup.

    final TextView dSTextView = (TextView)findViewById(R.id.annoyingTextView);
dSTextView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

    @Override
    public void onGlobalLayout() {
        dSTextView.getViewTreeObserver().removeOnGlobalLayoutListener(this);

        float lineHeight = dSTextView.getLineHeight();
        int maxLines = (int) (dSTextView.getHeight() / lineHeight);

        if (dSTextView.getLineCount() != maxLines) {
            dSTextView.setLines(maxLines);
        }

    }
});

You can read more about it here

Showy answered 14/3, 2016 at 3:22 Comment(0)
N
2

I know it's so late, but this is work like charm for me. add this code to your textview

android:ellipsize="marquee"
android:layout_weight="1"
Nomenclator answered 18/8, 2017 at 9:44 Comment(0)
I
1

I have this same problem, and its very annoying.

It only happens with Arabic text.

If you make the label multi-line and adding a \n at the end of your string, it would fix it, but the problem is that there would be a big gap between this label and the object below it, due to the fact that this field now has a new empty line below it.

A custom control can be done to get around that. But overall, this is an annoying bug.

Indispose answered 6/11, 2012 at 10:53 Comment(1)
If you have a NEW question, please ask it by clicking the Ask Question button. If you have sufficient reputation, you may upvote the question. Alternatively, "star" it as a favorite and you will be notified of any new answers.Wanton
C
1

I think there is very little you can do to get this working by altering the layouts. As I have found that some methods work only in some cases. I think it depends on the entire layout hierarchy and is not a one-size-fits-all solution. I have also noticed that it happens especially when you have a different font that you want to set to the TextView.

A sure shot method that I have experimented and tested is that you can set the font attributes in code after the view is inflated. I am assuming that you have a font in the assets/fonts folder that you want to you.

For eg in a Fragment:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState)
{
    View view = inflater.inflate(R.layout.fragment_view, container, false);
    TextView tv = (TextView)view.findViewById(R.id.text_view);
    tv.setText("Insert text that needs to be displayed");
    AssetManager assetManager = getContext().getAssets();
    Typeface typeFace = Typeface.createFromAsset(assetManager, "Fonts/OpenSans-Light.ttf");
    tv.setTypeface(typeFace , 0); // 0 is normal font
    tv.setPadding(10,  0, 10, 0); // This is not mandatory
}

And in an Activity:

@Override
protected void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(Resource.Layout.main_activity);
    TextView tv = (TextView)this.findViewById(R.id.text_view);
    tv.setText("Insert text that needs to be displayed");
    AssetManager assetManager = getContext().getAssets();
    Typeface typeFace = Typeface.createFromAsset(assetManager, "Fonts/OpenSans-Light.ttf");
    tv.setTypeface(typeFace , 0); // 0 is normal font
    tv.setPadding(10,  0, 10, 0); // This is not mandatory
}
Carolacarolan answered 2/5, 2016 at 12:7 Comment(0)
S
0

Best workaround for this is to add a dummy View of desired height (i.e. this will add padding itself) at the bottom of your view.

<TableRow
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:layout_marginLeft="5dp"
 android:layout_marginRight="5dp" >
     <View 
       android:layout_width="match_parent" 
       android:layout_height="30dp"/>
</TableRow>

Like in my case I added one more table row at the bottom of the view. Hope this could help someone.

Survivor answered 18/8, 2014 at 7:24 Comment(0)
C
0

Add padding to the bottom of the text view:

android:paddingBottom="24dp"
Claussen answered 27/8, 2019 at 23:54 Comment(0)
B
0

I had the same problem and found a handy solution. I get the number of lines of the TextView after rendering and set the height according to the number of lines. Here is the code.

TextView textView = (TextView) layout.findViewById(R.id.textView);
textView.setText(this.text);
textView.post(new Runnable() {
    @Override
    public void run() {
        int linesCount = textView.getLineCount();
        textView.setLines(linesCount);
    }
});
Blaze answered 17/9, 2020 at 8:8 Comment(0)
Z
0

For me, this solution worked like a charm.

The height and width of my outermost layout was set dynamically, so the TextView contained within got it's text cut even if I set android:maxLines in my xml (for different devices it was behaving differently).

After trying out different methods, finally I got a solution that fixed my issue.

Textview:

public class CustomTextView extends androidx.appcompat.widget.AppCompatTextView {
    public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
    public CustomTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public CustomTextView(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);
            this.setEllipsize(TextUtils.TruncateAt.END);
        }
    }
}

xml:

<com.myproject.android.customviews.CustomTextView
    android:id="@+id/tv_partner_description"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="top"
    android:textColor="@color/white"
    android:textSize="@dimen/text_small_medium" />
Zwolle answered 27/10, 2020 at 17:56 Comment(0)
U
0

create theme as for particular language like style-ar which cut-off textview:

<style name="EnnodaCustomTextView" parent="Widget.AppCompat.TextView">
        <item name="android:paddingTop">1dp</item>
        <item name="android:paddingBottom">1dp</item>
</style>

Apply it in you AppTheme to reflect in overall app for padding bottom, as :

    <item name="android:textViewStyle">@style/EnnodaCustomTextView</item>

Note : create same style name in default styles.xml with no item tags for padding..(where no need of extra padding )

Unguent answered 6/2, 2021 at 11:20 Comment(0)
A
-1

I finally fixed it!

I try to add String to the TextView in Service and then call scrollTo(), the last line be cut off!

The scrollTo() should be call in "Runnable", like:

private ScrollView mScrollView;
public void scrollToBottom()
{
    mScrollView = (ScrollView) findViewById(R.id.debug_textview_scrollview);
    mScrollView.post(new Runnable()
    {
        public void run()
        {
            mScrollView.fullScroll(View.FOCUS_DOWN);
        }
    });
}

I think it because in the monent of call scrollTo() in service, the update of TextView is not ready.

Amieva answered 1/10, 2015 at 3:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.