0

我在android應用程序中工作,我想在使用動畫效果滑動時使我的佈局的一部分可見和不可見。水平滑動以使佈局與動畫可見

這是我的佈局

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:weightSum="2" > 

     <LinearLayout 
      android:id="@+id/hiddenLayout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight=".3" 
      android:background="@android:color/black" 
      android:orientation="horizontal" 
      android:visibility="gone" > 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1.7" 
      android:background="@android:color/darker_gray" /> 
    </LinearLayout> 

</LinearLayout> 

默認命名佈局 「hiddenLayout」 的知名度已經一去不復返了。但是當我從左向右滑動時,它應該像ViewPager一樣以動畫效果顯示。它的能見度應該朝相反的方向滑動。

我該如何實現這一點。

回答

0

您的活動應該實現GestureDetector.OnGestureListener 您可以處理這裏面方法 -

@Override 
public boolean onFling(MotionEvent event1, MotionEvent event2, 
     float velocityX, float velocityY) { 

    boolean result = false; 
     try { 
      float diffY = e2.getY() - e1.getY(); 
      float diffX = e2.getX() - e1.getX(); 
      if (Math.abs(diffX) > Math.abs(diffY)) { 
       if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) { 
        if (diffX > 0) { 
         onSwipeRight(); 
        } else { 
         onSwipeLeft(); 
        } 
       } 
      } 
     } catch (Exception exception) { 
      exception.printStackTrace(); 
     } 
     return result; 
    } 
} 

隱藏佈局的知名度最後加動畫的看法..

+0

是否有可能與視圖尋呼機? – Arun

+0

實際上,這是一種解決方法,可以在不使用瀏覽器的情況下獲得類似效果。 – nikvs