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種意外行爲:
即使當抽屜被關閉,
HomeScreenFragment
完全覆蓋MenuFragment
,在MenuFragment
仍接收單擊事件。當抽屜打開並且
HomeScreenFragment
的按鈕位於屏幕的右上角時,它仍然會收到點擊事件,就好像它仍然在左側。即使按鈕位於右側,也可以點擊它,這意味着我需要點擊屏幕的左側。
不錯,我看過一些抽屜庫,但不喜歡它們中的任何一個。雖然之前沒有檢查過這個。謝謝。 – SimonSays