2015-09-29 6 views
0

У меня есть RelativeLayoutin верхний вид прокрутки, и теперь я хочу, когда вытаскиваем RelativeLayoutin, намекаем и подтягиваем RelativeLayoutin show. Как я? Мой 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

ý эм là Ĉu прокрутки вверх lÀ Иен, прокрутите вниз là пошел DJI đúng К.О.? vậy xem lại a Редактировать –

+0

Vâng a. e code theo nhưng mà lúc mình di chuyển scroll rồi giữ nó thì cái Rlayout_top đấy nó cứ hide show liên tục (như đèn nháy ấy: v). có cách nào khắc phục ko a? –

+0

để nó đỡ nháy e phải để sao cho scroll 1 đoạn nhất định mới hide/show view, em thu thay nhu sau số 25 là fix, e thử xem khoảng cách nào là hợp lí: if (scrollY> (lastPosition + 25)) {// скрыть RelativeLayout } еще если (scrollY <(lastPosition -25)) {// показать свою точку зрения } –

Смежные вопросы