【发布时间】:2013-10-08 06:43:49
【问题描述】:
我想在用户向上滚动列表视图时隐藏顶部栏,然后在用户向下滚动时使其再次可见。它与向下滚动时出现的 Google Plus 底部菜单相同,只要我们向上滚动它就会消失。我试过滚动,它给了我第一个可见的项目。但这对我没有帮助,因为它需要完全滚动列表视图项目才能获得前一个可见项目。请任何人帮助我,我非常陷入这个问题。
【问题讨论】:
标签: android android-actionbar scrollview
我想在用户向上滚动列表视图时隐藏顶部栏,然后在用户向下滚动时使其再次可见。它与向下滚动时出现的 Google Plus 底部菜单相同,只要我们向上滚动它就会消失。我试过滚动,它给了我第一个可见的项目。但这对我没有帮助,因为它需要完全滚动列表视图项目才能获得前一个可见项目。请任何人帮助我,我非常陷入这个问题。
【问题讨论】:
标签: android android-actionbar scrollview
一种可能的解决方案是在您的 ListView 下方添加一个视图(带有 textView 或 ImageView 的布局):
<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" />
权重对于显示这两个组件很重要。 之后,实现listView的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) {
}
});
当它到达最后一行时,setVisibility(View.GONE) 为底部视图。 如果你想再次显示这个视图,当用户向上滚动时,修改代码。当然,您可以使用其他布局、textView 或其他东西。
更新
我玩了一下a布局,你的布局文件还有另一种解决方案,底部View覆盖listView,所以这个textView的删除很顺利。
<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>
更多详情请参考HERE
【讨论】: