每次我向上或向下滚动列表时,我都会隐藏(或取消隐藏)一些视图OnScrollListener
。这是附加到我的ListView
.
lv.setOnScrollListener(new OnScrollListener() {
private int mLastFirstVisibleItem;
private boolean mIsScrollingUp = true;
private LinearLayout ll = (LinearLayout) getActivity()
.findViewById(R.id.llSearchPlaces);
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
if (view.getId() == lv.getId()) {
final int currentFirstVisibleItem = lv
.getFirstVisiblePosition();
if (currentFirstVisibleItem > mLastFirstVisibleItem) {
if (mIsScrollingUp == true) {
mIsScrollingUp = false;
Log.i("a", "scrolling down...");
floatingActionButton.hide();
Animation animation = new TranslateAnimation(0, 0,
0, 200);
animation.setDuration(300);
animation
.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationEnd(
Animation animation) {
ll.setVisibility(View.INVISIBLE);
}
@Override
public void onAnimationRepeat(
Animation animation) {
}
@Override
public void onAnimationStart(
Animation animation) {
}
});
ll.startAnimation(animation);
}
} else if (currentFirstVisibleItem < mLastFirstVisibleItem) {
if (mIsScrollingUp == false) {
mIsScrollingUp = true;
floatingActionButton.show();
Log.i("a", "scrolling up...");
Animation animation = new TranslateAnimation(0, 0,
200, 0);
animation.setDuration(400);
animation
.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationEnd(
Animation animation) {
}
@Override
public void onAnimationRepeat(
Animation animation) {
}
@Override
public void onAnimationStart(
Animation animation) {
ll.setVisibility(View.VISIBLE);
}
});
ll.startAnimation(animation);
}
}
mLastFirstVisibleItem = currentFirstVisibleItem;
}
}
});
布局:
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ListView
android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fadeScrollbars="true"
android:listSelector="#00000000"
android:scrollbars="none" />
</android.support.v4.widget.SwipeRefreshLayout>
自从我添加了,当我在上面的侦听器中SwipeRefreshLayout
时,我什么也没得到。Log
我怎样才能同时使用这两个项目?
编辑:这似乎是我需要的,但我不能让它仍然工作
作为那篇文章的一部分,我在 中添加了这个onScroll
,但它似乎不起作用。
if (firstVisibleItem == 0) {
swipeLayout.setEnabled(true);
} else {
swipeLayout.setEnabled(false);
}
EDIT2:这是问题的核心:似乎该onScroll
方法在 Activity 首次启动并且列表加载时触发,然后再也不加载了。