How to remove Click location after TranslateAnimation? - android

I have full screen RelativeLayout that contains the following:
1. FrameLayout, full screen, displaying content.
2. LinearLayout, act as a control menu, stay on top of the content #1, must be able to slide or fade in/out on request(I actually have two of these. One at the top of the screen, another at the bottom).
I have the view display correctly, the menu controller slide/fade in and out when menu button pressed. But when I slide and fade the view out, the click action remain. How do I remove this action?
I tried to call menuLayout.setVisibility(View.GONE); but the action remains.
I read some issue with TranslateAnimation but I cannot get it to work.
Can someone tell me how do I fix this? Example would be appreciated.
XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#99000000"
android:layout_alignParentLeft="true"
android:gravity="center_vertical"
android:id="#+id/contentFrame"
>
<ViewSwitcher
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/viewSwitch">
<include layout="#layout/main_car" />
</ViewSwitcher>
</FrameLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="43dp"
android:background="#drawable/um_top_bar"
android:layout_alignParentTop="true"
android:id="#+id/topMenu"
android:gravity="top"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/um_btn_home"
android:id="#+id/homeMainBtn" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/exp_menu_btn"
android:id="#+id/menuMainBtn" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FF000000"
android:layout_alignParentBottom="true"
android:id="#+id/bottomMenu"
android:gravity="top"
>
<include layout="#layout/menu_bottom" />
</LinearLayout>

Ok, I got it to work at last. For anyone who may face the same problem, here's what I did.
I place empty layer and separate all menu content into separate XML file.
Here's the code:
/** Resetting bottom menu content */
private void resetBottomMenu(boolean isOpen){
bottomMenu.removeAllViews();
bottomMenu.addView(loadBottomMenu(isOpen));
// Control event handler goes here.
}
/** Load bottom menu content from XML */
private LinearLayout loadBottomMenu(boolean isOpen){
LinearLayout result = null;
if(isOpen){
result = (LinearLayout)View.inflate(this.getApplicationContext(), R.layout.menu_bottom_open, null);
}else{
result = (LinearLayout)View.inflate(this.getApplicationContext(), R.layout.menu_bottom, null);
}
return result;
}
Every time I want to slide menu in, I called resetBottomMenu then start animation on bottomMenu. If I want to close the menu, I start animation then resetBottomMenu.
It's important to remove child view in that Layout since that will remove the click action.
P.S. I'm not sure if this is the best way of doing it but I can confirm that it works. I have three menu that need to be fade/slide and they work perfectly now :)

Related

Circular reveal over top of other views gives error "cannot start this animator on a detached view"

i had gone through research about for couple of days but didn't get it resolved. Problem in this Question is similar to mine but I couldn't solve my issue using this either.
I had tried to get the circular reveal effect just like whatsapp where the revealed view will be inflated over the top of other views. In my case when I apply the animation on a layout already present in the layout.xml of current java class then its work fine but the problem is that the revealing layout which in my case is LInearLayout will push the other contents(which are under it) down and make place for it.
My layout in this case is as follow,
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<io.codetail.widget.RevealFrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/reveal_items"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageButton
android:layout_width="70dp"
android:layout_height="70dp"
android:background="#drawable/icon_camera" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Gallery" />
</LinearLayout>
<!-- Other 2 icons here-->
</LinearLayout>
</io.codetail.widget.RevealFrameLayout>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter Name" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="OK" />
LinearLayout/>
my reveal layout will push the EditText and button down to make place for it but i want to reveal over the top of them..
Then I tried to put the revealing view code in another reveal-layout.xml file and inflate that layout to a View(LinearLayout in my case) created in javacode. And then try to apply the revealing effect on this LinearLayout but it gives me this "cannot start this animator on a detached view" exception.
My revealing-layout.xml looks like
<io.codetail.widget.RevealFrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/reveal_items"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageButton
android:layout_width="70dp"
android:layout_height="70dp"
android:background="#drawable/icon_camera" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Gallery" />
</LinearLayout>
<!-- Other 2 icons here-->
</LinearLayout>
</io.codetail.widget.RevealFrameLayout>
In button click i call function revealView();
which looks as below,
public void revealView()
{
int cx = (mRevealView.getLeft() + mRevealView.getRight());
int cy = mRevealView.getTop();
int radius = Math.max(mRevealView.getWidth(), mRevealView.getHeight());
// and all animations here, the animator is working fine so i did not put the code here
}
If i initialize mRevealView in my MainActivity onCreate() methoed as, mRevealView=(LinearLayout)findviewbyid(R.id.reveal_items) and inflate and assign view to it then the animator will work fine on this view. But when i try to create new layout like,
mRevealView=new LinearLayout(this) and set its parameters etc everything then it will gives this error when i apply animator on it.
Cannot start this animation on a detached view.
What I am doing wrong here can anybody suggest me.
Try to put your reveal code in a ViewTreeObserver of intended reveal-layout, something like this:
boolean reveal = false;
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
reveal = true;
}
});
LinearLayout layout = (LinearLayout) findViewById(R.id.reveal_items);
layout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
if(reveal) {
reveal = false;
// start reveal animation here
// ...
}
// for SDK >= 16
ll.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
To achieve a similar effect like whatsapp using the Circular Effect like whatsapp library you mentioned i first set my parent view as FrameLayout. This parent Framelayout includes two childrens first is LinearLayout and second is FrameLayout(Here comes the code you want to display on top of view written in LinearLayout). Write all your code which you want display on the screen in the first LinearLayout and the reveal effect code in second FrameLayout as i mentioned. Its simply the use of FrameLayout property. You are good to go.
You can use the same java code provided in the discription of the library.

DrawerLayout with two drawers: Right one "jumping" when left one is opened?

My application has a DrawerLayout with two drawers in it, one on the left for nav and one on the right for notifications. When the application goes through a cold start and I swipe the left drawer open, the right drawer jumps from the far left of the screen to the right.
It looks like this: http://i.imgur.com/mhoJ7MZ.gifv
As shown in the video, I've tried using DrawerLayout's isDrawerOpen and isDrawerVisible methods to try to see if it actually thinks the right drawer is open when it's not (since it seems to be "closing" the drawer when the left one is opened), but I didn't get anything useful from that.
What's causing the weird jump?
My activity's XML is below, the full code is here.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
...
</LinearLayout>
<LinearLayout
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#ACFF0000"
android:gravity="center"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LEFT DRAWER"
android:textSize="24sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/right_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#AC00FF00"
android:gravity="center"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RIGHT DRAWER"
android:textSize="24sp" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
The issue comes from the android:visibility="gone" element on the LinearLayouts -- For some reason having visibility set to gone conflicts with the DrawerLayout's logic for if the view is showing or not, so it tries to hide it.
Taking that out of the XML causes everything to look the same (since DrawerLayout looks at the layout_gravity to decide which child views are drawers and hides them itself) and not have the weird jump.

how to make Arc menu with scroll?

I need a arc menu like above image but it is not scrolling. I need that i can add more menus and it should come from bottom while scrolling.And these menu will come after a tap on center button. Please help me.
I have a SemiCircularRadialMenu and there are individual fragments for every menu. I am opening fragments on clicking different menu but when I click on fragment, it also covers that SemiCircularRadialMenu. I want that when I click on the fragment, there should be no effect on SemiCircularRadialMenu.
My XML Code is given below (XML)
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
<com.touchmenotapps.widget.radialmenu.semicircularmenu.SemiCircularRadialMenu
android:id="#+id/radial_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:padding="5dp" />
Code link for Semi Circular menu http://hasmukhbhadani.blogspot.in/2014/04/radial-menu-semi-circular-radial-menu.html (CIRCULAR OUTPUT SCREEN: is Semi Circular menu )

Combining NavigationDrawer and SlidingPaneLayout - SlidingPaneLayout from the right possible?

I'm using a NavigationDrawer as main menu in my app. Some of my fragments use the SlidingPaneLayout.
At the moment, I show the NavigationDrawer on the right and the SlidingPaneLayouton the left, always a little bit visible.
But I would like to have the NavigationDrawer on the left side and the SlidingPaneLayout on the right side (like in Hangouts) always a little bit visible.
Question:
I know how to get the NavigationDrawr to the other side, but I can't find out how (if possible) to move the SlidingPaneLayout to the right side? So that it slides in from the right...
my solution
<android.support.v4.widget.SlidingPaneLayout
android:id="#+id/sliding_pane_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/fragment_main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="left"
android:layout_marginRight="0dp"
android:orientation="vertical" >
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
layout="#layout/card_toast_container" />
<FrameLayout
android:id="#+id/fragment_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<!-- marginLeft: set it to width - 150 in your code!!! -->
<FrameLayout
android:id="#+id/fragment_slider"
android:layout_width="150dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:layout_marginLeft="0dp" />
</android.support.v4.widget.SlidingPaneLayout>
and use some wrapping methods like for example following, for easier and more readable code:
public boolean isSliderMenuShown()
{
return !mSlidingLayout.isOpen();
}
public static void openSlider(boolean isSliderLeft, MySlidingPaneLayout slidingLayout)
{
slidingLayout.closePane();
}
public static void closeSlider(boolean isSliderLeft, MySlidingPaneLayout slidingLayout)
{
slidingLayout.openPane();
}
Set this to view inside navigation drawer:
android:layout_gravity="left"
you can try keeping it open in the start with:
SlidingPaneLayout sp = (SlidingPaneLayout) findViewById(R.id.spl);
sp.openPane();
Also keep your main content on the left and menu on the right
After my research and test, android.support.v4.widget.SlidingPaneLayout can't swipe out from right to left. The only effect is swiping out from left to right.
No matter whether android:layout_gravity= is start left end or right.
You can achieve that by adding the layout direction for you Slidingpanel layout
layout = (SlidingPaneLayout) findViewById(R.id.sliding_pane_layout);
layout.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
before that make sure you have added a property android:supportsRtl="true" for your manifest file.
Step-1
In order to support RTL in your app, you first need to add android:supportsRtl="true" to the element in your manifest file.
Step-2
Add RTL support in SlidingPaneLayout
android:layoutDirection="rtl"
Step-3
Add LTR support in child views of SlidingPaneLayout
android:layoutDirection="ltr"
<SlidingPane
android:id="#+id/slidingPanelLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutDirection="rtl">
<include
layout="#layout/left_drawer"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layoutDirection="ltr" />
<include
layout="#layout/view_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layoutDirection="ltr"
/>
</SlidingPane>
Note: add LTR support in both left_drawer.xml, view_container.xml

Visibility trouble with framelayout children

I have a problem with the children of my FrameLayout when I change their visibility dynamically :
The FrameLayout is composed with a simple ScrollView that is allways visible and a RelativeLayout that represents a search bar and that is gone by default but that can be set to visible dynamically if the user press a button on the action bar.
So when the user press the action bar button and the search bar is GONE, there is no problem, the search bar appears like it has to. But when the search bar is VISIBLE impossible to make her disappear. I don't know why because the state of the bar is well set to GONE when I display it in the log but it's like the FrameLayout was not refreshed.
Someone knows that probleme or has a solution to mine ?
There is the code:
....
<FrameLayout
android:id="#+id/frame_layout_movie_detail"
android:layout_below="#+id/movie_actionbar">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
....
<ImageView
android:id="#+id/iv_movie_detail_poster"
android:scaleType="fitCenter"
android:src="#android:drawable/ic_menu_report_image" />
....
</RelativeLayout>
</ScrollView>
<include
android:id="#+id/include_search_bar_movie"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
layout="#layout/search_bar" />
</FrameLayout>
....
search_bar.xml:
<RelativeLayout
<EditText />
<ImageButton />
</RelativeLayout>
the code to display and hide the search bar:
private void onDisplaySearchBar() {
if (search_bar.getVisibility() == View.GONE)
search_bar.setVisibility(View.VISIBLE);
else
search_bar.setVisibility(View.GONE);
search_bar.invalidate();
}
thanks

Categories

Resources