拉ScrollView时隐藏RelativeLayout

时间:2015-09-29 03:21:16

标签: android

我有RelativeLayoutin顶级滚动视图,现在我想拉下RelativeLayoutin提示并拉出RelativeLayoutin show。 我怎样做? 我的xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    tools:context="${relativePackage}.${activityClass}" >

    <RelativeLayout
        android:id="@+id/Rlayout_top"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="5dp" />
    </RelativeLayout>

    <ScrollView
        android:id="@+id/Scrollview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/Rlayout_top"
        android:paddingBottom="20dp" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >
        </LinearLayout>
    </ScrollView>

</RelativeLayout>
谢谢!

1 个答案:

答案 0 :(得分:0)

试试这个:

private float lastPosition=0;
    scrollView.getViewTreeObserver().addOnScrollChangedListener(new OnScrollChangedListener() {
    @Override
            public void onScrollChanged() {
                int scrollY = rootScrollView.getScrollY(); //for verticalScrollView

               if(scrollY >lastPosition){
            // hide your RelativeLayout
            }else {
            //show your view

            }
    lastPosition=scrollY
        });