Search code examples
androidandroid-linearlayouttextviewandroid-2.3-gingerbread

TextView does not show or cuts text in 2.3, works fine in 3.0+


So this is a brain teaser, I have a ListView with a custom layout, the issue is that the values are not showing correctly(See pics). First of all, all values in the list in 3.0+ are populated fine. In 2.3 & 2.2 the first item in the list is properly populated but from the second on the text is cut off or doesn't display at all. Another thing is that if I try to scroll slowly up or down the values start showing but obviously this is not the behavior needed.

This is the xml layout for each item in the list

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

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="3"
    android:orientation="horizontal"
    android:paddingTop="8dip">

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

        <TextView
            android:id="@+id/toptext"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:textSize="20sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/bottomtext"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1"
            android:ellipsize="marquee"
            android:singleLine="true" />
    </LinearLayout>

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

        <TextView
            android:id="@+id/value1"
            android:layout_width="wrap_content"
            android:layout_height="0dip"
            android:layout_gravity="right"
            android:layout_marginRight="6dip"
            android:layout_weight="1"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/value2"
            android:layout_width="wrap_content"
            android:layout_height="0dip"
            android:layout_gravity="right"
            android:layout_marginRight="6dip"
            android:layout_weight="1"
            android:textSize="15sp" />
    </LinearLayout>
</LinearLayout>

<LinearLayout
    android:id="@+id/value3"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/valu4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    </ImageView>
</LinearLayout>

<LinearLayout
    android:id="@+id/value5"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="2"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/value6"
        android:layout_width="wrap_content"
        android:layout_height="10dp" >
    </ImageView>

    <ImageView
        android:id="@+id/value7"
        android:layout_width="wrap_content"
        android:layout_height="10dp" >
    </ImageView>

    <ImageView
        android:id="@+id/value8"
        android:layout_width="wrap_content"
        android:layout_height="10dp" >
    </ImageView>
</LinearLayout>

<LinearLayout
    android:id="@+id/value9"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="2"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/value10"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="left"
        android:textSize="8dp"
        android:textStyle="bold" >
    </TextView>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:text="TextHere"
        android:textSize="8dp"
        android:textStyle="bold" >
    </TextView>

    <TextView
        android:id="@+id/Value11"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="right"
        android:textSize="8dp"
        android:textStyle="bold" >
    </TextView>
</LinearLayout>

</LinearLayout>

And this is the xml for the main:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingLeft="8dip"
android:paddingRight="8dip" 
android:theme="@android:style/Theme.Black.NoTitleBar">


<ListView
    android:id="@+id/android:list"
    android:layout_width="fill_parent"
    android:layout_height="1dip"
    android:layout_weight="7"
    android:scrollbars="none"
    android:transcriptMode="normal">
</ListView>
</LinearLayout>

Thanks for any help in advance, sorry I cannot post pics until I reach level 10 (noob here <--)

Pic links added! Before scrolling: https://i.sstatic.net/6bdWp.jpg

After scrolling: https://i.sstatic.net/w0nWd.jpg


Solution

  • Ok, so I know that with the information provided in the question there was no way of figuring out the answer. But just in case someone else experiences this strange behavior this is what was causing the issue.

    in the onCreate method i had the line:

    getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
    

    causing the textviews to cut or not show the text unless the view was scrolled. The action bar was not implement until API 11, and 2.3 is only 9. But there was no waring compiling or deploying the project.

    Solution replace the line above with:

    if (android.os.Build.VERSION.SDK_INT >=android.os.Build.VERSION_CODES.HONEYCOMB) {
        getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
    }
    

    After the change, the text in the listview was displaying correctly.