0

我有一个带有标题面板和列表视图的布局。

这是布局。

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

在 onTouchListener 中,我删除并添加了 RelativeLayot 标头。

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;
}

删除标题后,列表视图中的所有显示项目都会重新加载。我有一个图像和文本,它是从网络加载的,每次重新加载文本和图像时。

如何关闭此重新加载?

4

1 回答 1

1

据我说,这是因为您的 headerView 在顶部对齐(即使在线性布局上)并且列表视图在其下方。因此,当您删除标题视图时,它会使列表视图更改其高度,因此所有视图都被重绘。

作为一种解决方案,您可以在 headerview 后面使用一个虚拟视图(需要将父视图更改为 RelativeLayout),其高度与原始标题视图相同,现在您的列表视图将低于该虚拟标题视图而不是原始标题看法。

像这样的东西。

<?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"/>
于 2013-01-04T14:15:34.120 回答