Textview Populated Dynamically Cutting Off Last Line Of Text
Solution 1:
I have the same problem. I have found a workaround. Append a new line "\n" to your text. This will always show all of your text.
Solution 2:
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"?><LinearLayoutxmlns: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"
><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center_horizontal"android:orientation="vertical"><TextViewandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:textColor="#4f4f4f"android:id="@+id/contentTextView"/><ImageViewandroid: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"?><LinearLayoutxmlns: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"
><LinearLayoutandroid:layout_width="263dp"android:layout_height="wrap_content"android:layout_gravity="center_horizontal"android:orientation="vertical"><TextViewandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:textColor="#4f4f4f"android:id="@+id/contentTextView"/><ImageViewandroid: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"?><LinearLayoutxmlns: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"
><LinearLayoutandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center_horizontal"android:orientation="vertical"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:textColor="#4f4f4f"android:id="@+id/contentTextView"/><ImageViewandroid: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.
Solution 3:
Have you tried surrounding your TextView directly with a LinearLayout, with width and height set to wrap_content ?
It worked for me...
Solution 4:
I had a different problem but similarly related. Here is the solution that I think works for what you need as well. You can use a global layout listener for a TextView in any type of ViewGroup.
finalTextViewdSTextView= (TextView)findViewById(R.id.annoyingTextView);
dSTextView.getViewTreeObserver().addOnGlobalLayoutListener(newViewTreeObserver.OnGlobalLayoutListener() {
@OverridepublicvoidonGlobalLayout() {
dSTextView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
floatlineHeight= dSTextView.getLineHeight();
intmaxLines= (int) (dSTextView.getHeight() / lineHeight);
if (dSTextView.getLineCount() != maxLines) {
dSTextView.setLines(maxLines);
}
}
});
You can read more about it here
Solution 5:
Have you tried
android:singleLine="false"
Post a Comment for "Textview Populated Dynamically Cutting Off Last Line Of Text"