TextView dynamically fills the last line of text

I'm not sure this is just the "last line", but we have an application with a TextView with a width of fill_parent, a height of wrap_content. The text is placed there dynamically from Java code. The last line of text simply does not appear, although there is a lot of space in the layout. It is inside a rather deep hierarchy of views, so my hunch is a measure of logic, in which everything went bad, but it's rather complicated. We need to guess how many lines will be in the text and set "android: lines" accordingly to make it work.

Has anyone seen this? In code, see Id 'contentTextView' at the bottom. If I choose android: lines, the last line of text will disappear.

<?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"
        >

    <include android:id="@+id/incHeader" layout="@layout/header"/>

    <FrameLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">

        <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical">

            <ImageView
                    android:layout_width="fill_parent"
                    android:layout_height="101dp"
                    android:background="@drawable/headershadow"/>

            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:visibility="invisible"
                    android:layout_weight="1"/>


            <ImageView
                    android:layout_width="fill_parent"
                    android:layout_height="101dp"
                    android:background="@drawable/footershadow"/>

        </LinearLayout>

        <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/gybcontentback"
                android:layout_gravity="center_horizontal"
                android:orientation="vertical">

            <include android:id="@+id/gybHeaderInclude" layout="@layout/gybcontentheader"/>


                <TextView
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:textColor="#4f4f4f"
                        android:paddingLeft="15dp"
                        android:paddingRight="15dp"
                        android:lines="9"
                        android:id="@+id/contentTextView"/>

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

        </LinearLayout>

    </FrameLayout>


    <include android:id="@+id/incFooter" layout="@layout/menu"/>

</LinearLayout>

Java-. TextView Java onCreate.

@Override
protected String body()
{
    return "Rascal Flatts and The Jason Foundation, Inc. are working together to prevent suicide.\n\n" +
            "Your Battle Buddy (or family member) may need a friend.\n\n" +
            "Take the pledge to B1.";
}

,

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(contentView());
    wireMenu();

    TextView headerText = (TextView) findViewById(R.id.gybHeaderText);
    if(headerText != null)
        headerText.setText(header());

    ((TextView) findViewById(R.id.contentTextView)).setText(body()); // This is where the text is set
}

, . , , , . , , "".

+5
7

. , :

<?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>

, , , LinearLayout ImageView . - TextView . , , . , , , . - . , . 263 ( mdpi), , 263dp wrap_content , .

<?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>

TextView wrap_content , , .

<?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>

, . , , , .

+1

. . "\n". .

+7

TextView LinearLayout, , wrap_content?

...

+2

android:singleLine="false" 
0

, . , , , , . TextView 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);
        }

    }
});

0

android: padding

TextView.

0

TextView FrameLayout ( ). , .

0

All Articles