2012-11-22 29 views
0

我想創建一個類似於Facebook應用的抽屜功能,並帶有兩個疊加片段。疊加碎片對意外事件做出反應以點擊事件

主要佈局看起來如下:

<merge 
    xmlns:android="http://schemas.android.com/apk/res/android" > 

    <fragment 
     android:id="@+id/menu" 
     android:name="ch.simon.drawertest.MenuFragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginRight="80dp" /> 
    <fragment 
     android:id="@+id/home" 
     android:name="ch.simon.drawertest.HomeScreenFragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
</merge> 

家庭片段包含在打開的抽屜左上角的按鈕。 HomeScreenFragment內部的TranslateAnimation會發生打開。

public void open(){ 
    translateTo(canScrollXBy()); 
} 

public void close(){ 
    translateTo(0); 
} 

private void translateTo(int x){ 
    Log.e(TAG, "Translate from " +mTranslated +" to " +x); 
    TranslateAnimation anim = new TranslateAnimation(mTranslated, x, 0, 0); 
    anim.setDuration(500); 
    anim.setFillAfter(true); 
    mRootView.startAnimation(anim); 
    mTranslated = x; 
} 

開啓和關閉工作正常,但我觀察2種意外行爲:

  1. 即使當抽屜被關閉,HomeScreenFragment完全覆蓋MenuFragment,在MenuFragment仍接收單擊事件。

  2. 當抽屜打開並且HomeScreenFragment的按鈕位於屏幕的右上角時,它仍然會收到點擊事件,就好像它仍然在左側。即使按鈕位於右側,也可以點擊它,這意味着我需要點擊屏幕的左側。

回答

0

爲此,您可以使用庫SlidindMenu來執行此操作。它像一個魅力。或者你可以從這個庫的代碼激發你。

+0

不錯,我看過一些抽屜庫,但不喜歡它們中的任何一個。雖然之前沒有檢查過這個。謝謝。 – SimonSays