0

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 つの予期しない動作が見られます。

  1. ドロワーが閉じられ、 が をHomeScreenFragment完全に覆っているMenuFragment場合MenuFragmentでも、 はクリック イベントを受信します。

  2. ドロワーが開いていて、からのボタンHomeScreenFragmentが画面の右上隅にある場合でも、まだ左側にあるかのようにクリック イベントを受け取ります。Button が右側にある場合でも、それをタップするには、画面の左側をタップする必要があります。

4

1 に答える 1

0

これには、ライブラリSlidindMenuを使用してこれを行うことができます。それは魅力のように機能します。または、このライブラリのコードからインスピレーションを得ることができます。

于 2012-11-22T21:55:31.517 に答える