Android 滚动时在顶部隐藏LinearLayout
这是我的布局:Android 滚动时在顶部隐藏LinearLayout,android,listview,scroll,Android,Listview,Scroll,这是我的布局: <?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" >
<?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" >
<LinearLayout
android:id="@+id/featuredContent"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:background="#ccc"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="@+id/panelpager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</LinearLayout>
我们会认为这个观点是不存在的。因此,在它的位置上不会有空间。与View.INVISIBLE不同,reserve position为空时不可见。您的意思是当您滚动到右下角时?您想在滚动到右下角时隐藏线性布局吗。抱歉。您可以使用
addHeader()
方法将featuredContent作为标题添加到ListView
中,而不是使用单独的视图。
listNews.setOnScrollListener(new AbsListView.OnScrollListener() {
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
View firstItem = listNews.getChildAt(0);
int top = (firstItem == null) ? 0 : firstItem.getTop();
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
}
});
LinearLayout ll = (LinearLayout)findViewById(R.id.featuredContent);
if (firstVisibleItem == 0)
{
ll.setVisibility(View.VISIBLE);
}
else
{
ll.setVisibility(View.GONE);
}