Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Click events on SlidingPaneLayout

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?

like image 858
user1788251 Avatar asked Aug 12 '13 07:08

user1788251


People also ask

What is slidingpanelayout?

SlidingPaneLayout is a control that uses Jetpack Window Manager to adapt to dual-screen and foldable devices. It can show two panes side-by-side (if there's room), otherwise only the first pane will be shown and the second can be revealed by the user (sliding from the side) or programmatically.

How do I show the secondary pane in slidingpanelayout?

SlidingPaneLayout now defaults to ‘closed’ - i.e., showing the list or primary pane. Calling open () or openPane () will now show the detail or secondary pane.

What's new in androidx slidingpanelayout?

androidx.slidingpanelayout:slidingpanelayout:1.2.0 is released. Version 1.2.0 contains these commits. Important changes since 1.1.0 SlidingPaneLayout is now fold-aware. On a foldable device, SlidingPaneLayout will automatically adjust the size of the two panes so that the panes are on either side of the fold, hinge, etc.

How does slidingpanelayout work on the surface duo?

On the Surface Duo, on a single screen the control behaves like any other device, where the panes will be side-by-side if they fit, otherwise shown independently. When the app is spanned, SlidingPaneLayout will automatically put each pane on a screen, on either side of the hinge.


2 Answers

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

like image 137
Monstieur Avatar answered Oct 13 '22 00:10

Monstieur


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>
like image 27
SurenSaluka Avatar answered Oct 13 '22 00:10

SurenSaluka