Abdulaziz Alnahhas Abdulaziz Alnahhas - 2 months ago 14
Android Question

Changing Layout Activity gets my app very slow

I'm not very experienced in android. In my

LayoutActivity
, I have a
LinearLayout
with vertical orientation includes two
TextView
and
ListView
like this:

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9"
android:orientation="vertical">
<TextView
android:id="@+id/not_connected_text"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="#01132e"
android:gravity="center_horizontal|center_vertical"
android:textStyle="bold"
android:text="Not Connected.."
android:textColor="#ffffff"/>
<TextView
android:id="@+id/global_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="3dp"
android:gravity="center"
android:background="@drawable/rounded_info_accent"
android:textSize="15sp"
android:textColor="#FF000000"
android:text="Today"/>
<ListView
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:cacheColorHint="#00000000"
android:listSelector="#00000000"
android:divider="#00000000"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/ChatlistView"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true" />
</LinearLayout>


I changed my layout by putting one
TextView
and the
ListView
inside a
RelativeLayout


<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9"
android:orientation="vertical">
<TextView
android:id="@+id/not_connected_text"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="#01132e"
android:gravity="center_horizontal|center_vertical"
android:textStyle="bold"
android:text="Not Connected.."
android:textColor="#ffffff"/>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/global_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="3dp"
android:gravity="center"
android:background="@drawable/rounded_info_accent"
android:textSize="15sp"
android:textColor="#FF000000"
android:text="Today" />
<ListView
android:layout_marginRight="5dp"
android:layout_marginLeft="5dp"
android:cacheColorHint="#00000000"
android:listSelector="#00000000"
android:divider="#00000000"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/ChatlistView"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</LinearLayout>


After this modification my
ListView
is now scrolling very very slow. Can any one help me with this please? Thanks.

Answer

In your case the Textview will be presented over the Listview that may cause to hide part of its first element, I guess when you scroll down, the system needs to regenerate the view each time which will take time. No other rational justification AFAIK.

Edit: You should add AlignParentTop to the TextView and set height of ListView to MatchParent.

Besides if you want the TextView to be on the top of ListView swap the definition of them in the XML.