Reputation: 8585
I have a layout with a header panel and a listview.
Here is the layout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/mainFragmentLayout">
<RelativeLayout
android:id="@+id/header"
android:background="@drawable/upper_panel"
android:layout_height="40dp"
android:layout_width="fill_parent">
<TextView android:id="@+id/news_label"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:gravity="left"
android:text="@string/news_label"
android:textSize="15sp"
android:textStyle="bold"
android:layout_marginLeft="54dp"
android:textColor="@color/white"
/>
<Button android:id="@+id/refreshButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@drawable/btm_refresh"
android:layout_centerVertical="true"
android:layout_marginRight="8dp"
/>
</RelativeLayout>
<ListView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="120"
android:id="@+id/feedMeMore"
android:fastScrollEnabled="false"
android:layout_gravity="center"/>
In onTouchListener I remove and add RelativeLayot header.
public boolean onTouch(View view, MotionEvent motionEvent) {
int action=motionEvent.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
startY = motionEvent.getY();
break;
case MotionEvent.ACTION_MOVE:
float nowY = motionEvent.getY();
if (startY - nowY > 10)
{
if (mainLayout.indexOfChild(headerView) >= 0)
mainLayout.removeView(headerView);
}
else if (startY - nowY < - 100)
{
if (mainLayout.indexOfChild(headerView) < 0)
mainLayout.addView(headerView, 0);
}
}
break;
}
return false;
}
When the header is removed all showed items in the listview is reloaded. I have there an image and text, that is loaded from web and every time it reload the text and the image.
How to turn off this reloading?
Upvotes: 0
Views: 228
Reputation: 3220
According to me that is because Your headerView is aligned at the top(even though on linearlayout) and list view is below it. So when you remove your header view it make listview changes its height, so all the views are redrawn.
As a solution you can use a dummy view behind the headerview(Need to change the parent view as RelativeLayout) whose height is as same as your original header view, and now your list view will be below that dummy header view and not the original header view.
Something like this.
<?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"
android:id="@+id/mainFragmentLayout">
<RelativeLayout
android:id="@+id/header"
android:background="@drawable/upper_panel"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_width="fill_parent">
<TextView android:id="@+id/news_label"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:gravity="left"
android:text="@string/news_label"
android:textSize="15sp"
android:textStyle="bold"
android:layout_marginLeft="54dp"
android:textColor="@color/white"
/>
<Button android:id="@+id/refreshButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@drawable/btm_refresh"
android:layout_centerVertical="true"
android:layout_marginRight="8dp"
/>
</RelativeLayout>
<RelativeLayout
android:id="@+id/dummyHeader"
android:background="@drawable/upper_panel"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_width="fill_parent"/>
<ListView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="120"
android:id="@+id/feedMeMore"
android:fastScrollEnabled="false"
android:layout_gravity="center"/>
Upvotes: 1