Click events on SlidingPaneLayout

2019-04-29 10:42发布

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?

3条回答
乱世女痞
2楼-- · 2019-04-29 10:47

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>
查看更多
贪生不怕死
3楼-- · 2019-04-29 10:54

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

查看更多
仙女界的扛把子
4楼-- · 2019-04-29 11:12

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

查看更多
登录 后发表回答