当scrollview在android中滚动时如何隐藏布局

时间:2017-01-05 11:49:33

标签: android scrollview onscrolllistener onscrollchanged

我是android的新手并且在滚动视图上工作,我有一个页脚布局,并且想要在滚动滚动视图时隐藏它,我已经尝试过onscrollStatechange我已经把那个视图的visibilty消失了,但是它没有工作。可以帮助我这样做?

  <ScrollView
        android:id="@+id/scr_product"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/rl_botm">
.
.
.
.</ScrollView>
<RelativeLayout
        android:id="@+id/rl_botm"
        android:layout_width="match_parent"
        android:layout_height="55dp"
        android:layout_alignParentBottom="true"
        android:background="@color/blue_extra_light"
        android:padding="5dp">

        <View
            android:id="@+id/sep"
            android:layout_width="match_parent"
            android:layout_height="0.75dp"
            android:background="@color/dark_grey" />

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/sep"
            android:layout_marginTop="5dp">

            <ImageView
                android:id="@+id/iv_share"
                android:layout_width="30dp"
                android:layout_height="35dp"
                android:layout_marginLeft="30dp"
                android:background="@drawable/ic_sare" />

            <View
                android:id="@+id/s1"
                android:layout_width="0.75dp"
                android:layout_height="20dp"
                android:layout_centerVertical="true"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:layout_toRightOf="@+id/iv_share"
                android:background="@color/grey_dark" />

            <ImageView
                android:id="@+id/iv_heart"
                android:layout_width="35dp"
                android:layout_height="35dp"
                android:layout_toRightOf="@+id/s1"
                android:background="@drawable/ic_hrt" />

            <View
                android:id="@+id/s2"
                android:layout_width="0.75dp"
                android:layout_height="20dp"
                android:layout_centerVertical="true"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:layout_toRightOf="@+id/iv_heart"
                android:background="@color/grey_dark" />

            <ImageView
                android:id="@+id/iv_report"
                android:layout_width="35dp"
                android:layout_height="35dp"
                android:layout_toRightOf="@+id/s2"
                android:background="@drawable/ic_flag" />

            <Button
                android:id="@+id/btn_rate_reviews"
                android:layout_width="150dp"
                android:layout_height="50dp"
                android:layout_alignParentRight="true"
                android:background="@drawable/btn_green_selector"
                android:padding="5dp"
                android:text="@string/rate_reviews"
                android:textColor="@color/white"
                android:textSize="16dp"
                android:textStyle="bold" />
        </RelativeLayout>

    </RelativeLayout>

的java

public class ProductDescriptionActivity extends Activity implements AbsListView.OnScrollListener {
.
.
.
.
 @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {
        rl_botm.setVisibility(View.VISIBLE);
    }

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        rl_botm.setVisibility(View.GONE);
    }

请帮我弄清楚。

1 个答案:

答案 0 :(得分:0)

试试这个,

scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
    @Override
    public void onScrollChanged() {
        if (scrollView != null) {
            if (scrollView.getChildAt(0).getBottom() <= (scrollView.getHeight() + scrollView.getScrollY())) {
                relativeLayout.setVisibility(View.VISIBLE);
            }
            else {
                relativeLayout.setVisibility(View.INVISIBLE);
            }
        }
    }
});