I have a top bar layout with a title, a vertical menu and a transparent background.
When btn_menu pressed btn_menu vertical menu opens with animation. When the menu is open, I set OnClickListener to a transparent background, which closes the menu when a transparent background is clicked. When closing the menu, I OnClickListener from the background view using:
mTopBarBg.setOnClickListener(null);
The problem is that it seems to remove all touch events behind its looks (set in the content_container main layout). For instance. a ViewPager that no longer detects swipes, or a ListView that no longer scrolls and can no longer be pressed while they are working correctly.
What's wrong?
in the upper panel fragment
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; } }
main layout
<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>
top panel layout
<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" > </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>
top panel with open menu

source share