滚动时在顶部隐藏LinearLayout

时间:2013-11-01 18:57:07

标签: 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" >

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

我已经将 AbsListView.OnScrollListener 实现到我的 ListView ,我可以获得第一项的Y,但是如何隐藏 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) {
    }
});

提前致谢!

1 个答案:

答案 0 :(得分:0)

LinearLayout ll = (LinearLayout)findViewById(R.id.featuredContent);

if (firstVisibleItem == 0)
{
    ll.setVisibility(View.VISIBLE);
}
else
{
    ll.setVisibility(View.GONE);
}

View.Gone会认为此视图从未存在过。因此,它的位置不会有空间。与View.INVISIBLE不同,保留位置为空。