2 つのオーバーレイ フラグメントを使用して、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>
ホーム Fragment には、ドロワーを開くボタンが左上隅に含まれています。開くには、 内の TranslateAnimation を使用しHomeScreenFragment
ます。
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
が画面の右上隅にある場合でも、まだ左側にあるかのようにクリック イベントを受け取ります。Button が右側にある場合でも、それをタップするには、画面の左側をタップする必要があります。