ヘッダー、垂直メニュー、透明な背景ビューを備えたトップ バー レイアウトがあります。
をbtn_menu
押すと、アニメーションを使用して垂直メニューが開きます。メニューが開いているOnClickListener
ときに、透明な背景をクリックするとメニューが閉じる透明な背景ビューを設定します。メニューを閉じるときは、次OnClickListener
を使用してバックグラウンド ビューから削除します。
mTopBarBg.setOnClickListener(null);
問題は、その背後にあるビューのすべてのタッチ イベントを削除するように見えることです (content_container
メイン レイアウトの で設定)。例えば。ViewPager
スワイプを検出しなくなったり、以前ListView
は正しく機能していたのに、スクロールせず、クリックできなくなったりします。
どうしたの?
トップバーのフラグメント
private void toggleMenu(int duration){
if(mMenuIsOpen){
TranslateAnimation anim1 = new TranslateAnimation(0,0,0,-(mHeight-mMenuVerticalOffset));
anim1.setFillAfter(true);
anim1.setDuration(duration);
mVerticalMenu.setAnimation(anim1);
AlphaAnimation anim2 = new AlphaAnimation(0.7f, 0.0f);
anim2.setFillAfter(true);
anim2.setDuration(duration);
mTopBarBg.setAnimation(anim2);
mTopBarBg.setOnClickListener(null);
mMenuIsOpen = false;
}
else{
TranslateAnimation anim1 = new TranslateAnimation(0,0,-(mHeight-mMenuVerticalOffset),0);
anim1.setFillAfter(true);
anim1.setDuration(duration);
mVerticalMenu.setAnimation(anim1);
AlphaAnimation anim2 = new AlphaAnimation(0.0f, 0.7f);
anim2.setFillAfter(true);
anim2.setDuration(duration);
mTopBarBg.setAnimation(anim2);
mTopBarBg.setOnClickListener(mBgClickListener);
mMenuIsOpen = true;
}
}
メインレイアウト
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/mainbg"
android:scaleType="centerCrop"/>
<FrameLayout
android:id="@+id/content_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="44dp" />
<FrameLayout
android:id="@+id/top_bar_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipChildren="false" />
</RelativeLayout>
トップバーのレイアウト
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000" >
<View
android:id="@+id/top_bar_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:visibility="gone" />
<LinearLayout
android:id="@+id/vertical_menu"
android:layout_width="50dp"
android:layout_height="match_parent"
android:layout_marginTop="44dp"
android:background="#ffffff"
android:orientation="vertical"
android:visibility="gone" >
<!-- vertical menu layout -->
</LinearLayout>
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="44dp"
android:background="#ffffff" >
<Button
android:id="@+id/btn_menu"
android:layout_width="50dp"
android:layout_height="44dp"
android:background="@drawable/menubtn" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="44dp"
android:layout_toRightOf="@id/btn_menu"
android:gravity="center" >
<ImageView
android:layout_width="130dp"
android:layout_height="44dp"
android:src="@drawable/logo" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
メニューが開いているトップバー