Click events on SlidingPaneLayout - android

I'm trying to use the SlidingPaneLayout. The left view is a ListFragment and the right view is a detail view. The layout is displayed correctly and I can slide it. But if the detail view is in front of the list and I click on it, the list in the background receives the click.
My layout looks like this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SlidingPaneLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/sliding_pane_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<fragment android:name="net.name.multiremote.RemoteListFragement"
android:id="#+id/fragment_remote_list"
android:layout_width="580dp"
android:layout_height="match_parent"
android:layout_gravity="left" />
<fragment
android:id="#+id/fragment_remote"
android:name="net.name.multiremote.RemoteFragment"
android:layout_width="850dp"
android:layout_height="match_parent"
android:layout_weight="1" />
</android.support.v4.widget.SlidingPaneLayout>
I use this code for setting up the click listener in the ListFragment
#Override
public void onListItemClick(ListView list, View view, int position, long id) {
iItemClickListener.onListFragmentItemClick(view, position);
}
How can I solve this?

Just add android:clickable="true" to the second Fragment or FrameLayout in the SlidingPaneLayout.

Locutus was correct.
Whatever the fragment on top, add the property
android:clickable="true"
so it will not pass the click event to the fragment below.
Thanks everyone for saving my time.
Here is my code. I have used an overridden layout but this works on regular sliding pane layout as well.
look at the 2nd fragment, I've added clickable true property.
<com.ironone.streaming.application.MySlidingPaneLayout
android:id="#+id/pane"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<FrameLayout
android:id="#+id/pane1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<FrameLayout
android:id="#+id/pane2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true" />
</com.ironone.streaming.application.MySlidingPaneLayout>

I have the same problem, I think it's a combination of "v4" version of Fragment and ListFragment and the SlidingPanelLayout...
If you change the import from "v4" to import normal "android.app.ListFragment;" and "import android.app.Fragment;" everything works.
Sorry for my english ;)

Related

How to set layoutTransition to animate correctly when item is removed from recycle view

I want the transition happens after item is removed from the list however when I remove the item transition happens earlier and it covers other items as shown in the GIF below.
my second issue is that when I use layoutTransition, when the fragment is created it expands with animation, how to avoid this at the beginning.
my layout is like like this:
<androidx.core.widget.NestedScrollView
android:id="#+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:fillViewport="true" >
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/constraintlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
and in the Fragment:(Kotlin):
scroll_view.layoutTransition.enableTransitionType(LayoutTransition.CHANGING)
scroll_view.layoutTransition.setStartDelay(LayoutTransition.CHANGING,300)
constraintlayout.layoutTransition.enableTransitionType(LayoutTransition.CHANGING)
constraintlayout.layoutTransition.setStartDelay(LayoutTransition.CHANGING,300)
but nothing changes, always same behavior
I found a way to fix the issue by using custom layout manager :D
the layout manager I used : https://github.com/BelooS/ChipsLayoutManager

RecyclerView Animate Layout Changes Not Working Fine

I have the next structure:
Activity 1:
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/FAB_add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</android.support.design.widget.CoordinatorLayout>
Activity 2:
Form to add new item to the recycler View.
XML of the RecyclerView:
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"/>
I create the item in the second Activity and use startActivityForResult to add the item in the activity one, and then call adapter.notifyItemInserted(0).
The problem is when the item is added, the insert animation does not working properly, but if I don't use the second activity and create the item in the first activity and add to the adapter, it works fine.
¿How can I solve this?
Your xml structure might be the problem, check your layout_behaviors and use of CoordinatorLayout
Android CoordinatorLayout
For a nice guide on how to use CoordinatorLayout and layout_behavior check this blog
I've also found that the use of android:animateLayoutChanges="true" can be very glitchy/buggy in a scrollable RecyclerView, I would suggest not using it. For non-scrollable RecyclerViews it works fine tho.

How to place an ActionBar on a SlidingMenu ( like in the Evernote app)?

I want to make slide menu that has ActionBar like in Evernote. In this app, Seem like it has 2 ActionBars(I'm not sure about it). One at main and another one is in the sliding menu.
Is there anyway to build 2 ActionBars like this? Or it's just a layout arrangement to resemble ActionBar look.
Thank for all your help and sorry for my english.
ps. I use ActionBarSherlock and SlidingMenu to achieve this, but I can't find the way to do it like in Evernote.
You wrote:
I use (...) SlidingMenu
If by SlidingMenu you mean Jeremy Feinstein's SlidingMenu, and you want to keep using this menu library, you can't use a 'real' ActionBar, since SlidingMenu's menu is implemented as a Fragment, named SlidingMenuFragment in the library. A Fragment can't hold an ActionBar.
You can create a layout which looks like an ActionBar. In SlidingMenuFragment's you set the layout file like so:
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup viewGroup = (ViewGroup) inflater.inflate(R.layout.sliding_menu,null);
In the menu's layout file, here called sliding_menu.xml, you can for example make a SearchView look like it's in an ActionBar by nesting it in a layout at the top. You then set that layout's background color/drawable to something different from the rest of the list. See below example (I'm aware nesting LinearLayouts isn't pretty...Just a quick example that uses the LinearLayout from the SlidingMenu example app to get the idea across):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#333333" >
<SearchView
android:id="#+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/list_padding"
android:paddingRight="#dimen/list_padding" />
</LinearLayout>
This will look like:
when open, where the light grey box to the right is part of the 'real' ActionBar.
Edit: You wrote in a comment:
The searchView example works Im having trouble getting a drop down menu to work in the same way.
The drop-down menu in the EverNote app looks like it's been implemented with a Holo-themed Spinner. Android Developers has a thorough introduction on how to add a Spinner to a layout. The Spinner's logic/java code would be placed in SlidingMenuFragment (if you go with the SlidingMenu library).
Ok I managed to do it with the help of Gunnar Karlsson who pushed me in the right direction Instead of a SearchView
I implemented an ImageButton like so:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#333333" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="60dp"
android:src="#drawable/ic_launcher"
android:onClick="showPopup" />
</LinearLayout>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="#dimen/list_padding"
android:paddingRight="#dimen/list_padding" />
</LinearLayout>
and in the my mainActivity I simply pulled this from the google sample code for creating a pop up menu:
public void showPopup(View v) {
PopupMenu popup = new PopupMenu(this, v);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.actions, popup.getMenu());
popup.show();
}
And it worked. Thank you Gunnar Karlsson.

Custom FrameLayout that adds items to sub FrameLayout?

I am trying to make some kind of button that can have content added to it like it is done to a FrameLayout. For example:
<ch.pboos.android.ui.ContentButton ...>
<LinearLayout ...>
<TextView .../>
<TextView .../>
</LinearLayout>
</ch.pboos.android.ui.ContentButton>
So far I made a view that xml file that would represent how i want the button to look like:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/white_button_margin"
android:paddingRight="#dimen/white_button_margin">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content" android:orientation="horizontal"
android:padding="#dimen/white_button_padding"
android:background="#drawable/channel_bg">
<FrameLayout android:id="#+id/content" ...>
<!-- content -->
</FrameLayout>
<ImageView ... android:src="#drawable/right_triangle" />
</LinearLayout>
</LinearLayout>
Now I would like to make a custom FrameLayout (ch.pboos.android.ui.ContentButton) that will add that view and allow me to add views into the content area of that xml above.
Any suggestions on how to get this working correctly?
1) Dispatch all touch events occurring on ContentButton to custom button via overriding dispatchTouchEvent. And add on click listener to this button (this helps you to recognize and handle only clicks, not e.g. moves)
2) override addView this way:
addView(...) {
if(inflatingInProgress) {
super.addView(view);
}
else {
// add view to #+id/content
}
}
// where flag inflatingInProgress initially = true and is set to false after
// finishing inflating the layout for ContentButton
Hope this helps. Good luck.

How to remove Click location after TranslateAnimation?

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 :)

Categories

Resources