2015-09-29 99 views
0

我有RelativeLayoutin頂部滾動視圖,現在我想拉下RelativeLayoutin提示並拉起RelativeLayoutin顯示。 我該怎麼辦? 我的XML隱藏RelativeLayout時拉動ScrollView

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

回答

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 
     }); 
+0

ýEMLàCU向上滾動LàHIEN,向下滾動Là了DJIđúngこ? vậyxemlạia編輯 –

+0

Vânga。 e code theonhưngmàlúcmìnhdichuyểnscrollrồigiữnóthìcáiRlayout_topđấynócứhide showliêntục(nhưđènnháyấy:v)。 cócáchnàokhắcphụcko a? –

+0

DJE NO DJOnháyË班派DJE騷町渦旋件1đoạn山一địnhMOI隱藏/顯示視圖,EM週四大公NHU秀所以25啦A修復,例如THU XEMkhoảngCACH淖LàHOP LI: 如果(scrollY>(一位置+ 25)){// 隱藏你的RelativeLayout }否則如果(scrollY <(-25一位置)){// 顯示您的視圖 } –

相關問題