我想在用户向上滚动列表视图时隐藏顶部栏,然后在用户向下滚动后立即使其再次可见。它与向下滚动时出现的Google Plus底部菜单相同,并且只要我们向上滚动,它就会出现。我已经尝试过滚动,它给了我第一个可见的项目。但这对我没有帮助,因为它需要完全滚动列表视图项目才能获得上一个可见项目。请任何人帮助我,我被这个问题严重困住了。
一个可能的解决方案是在列表视图下添加一个视图(具有文本视图或图像视图的布局):
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
<LinearLayout
android:id="@+id/viewid"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0" />
权重对于显示这两个组件很重要。之后,实现列表视图的 onScrollListener。
setOnScrollListener(new OnScrollListener() {
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
//get the showed item num, and if its equal to total, you can hide the view
//get a reference to your viewid
viewid.setVisibility(View.GONE);
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
});
当它到达最后一行时,设置底部视图的可见性(View.GONE)。如果要再次显示此视图,请在用户向上滚动时修改代码。当然,您可以使用其他布局、文本视图或其他内容。
更新
我稍微玩了一下布局,您的布局文件还有另一种解决方案,其中底部视图覆盖了列表视图,因此删除此文本视图很流畅。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
<TextView
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="5dp"
android:background="#ffffff"
android:layout_alignParentBottom="true"
android:text="..." />
</RelativeLayout>
有关更多详细信息,请参阅此处