0

I have sliding pane layout

<android.support.v4.widget.SlidingPaneLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/slidingPaneLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <fragment
        android:id="@+id/first_fragment"
        android:layout_width="@dimen/first_pane_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        class="com.example.example.FirstFragment"
        tools:layout="@layout/fragment_first" />

    <fragment
        android:id="@+id/second_fragment"
        android:layout_width="@dimen/second_pane_width"
        android:layout_weight="1"
        android:layout_height="match_parent"
        class="com.example.example.SecondFragment"
        tools:layout="@layout/fragment_second`enter code here`" />

</android.support.v4.widget.SlidingPaneLayout>

This is my onCreate method:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    slidingPaneLayout = (SlidingPaneLayout) findViewById(R.id.slidingPaneLayout);
    slidingPaneLayout.setPanelSlideListener(this);
    slidingPaneLayout.setParallaxDistance(PARALLAX_DISTANCE);
    slidingPaneLayout.setShadowDrawable(getResources().getDrawable(R.drawable.shadow));

    secondFragment = (SecondFragment) getFragmentManager().findFragmentById(R.id.second_fragment);
    firstFragment = (FirstFragment) getFragmentManager().findFragmentById(R.id.first_fragment);

    if (savedInstanceState == null) {
        firstFragment.selectItem(0);
        if (slidingPaneLayout.isSlideable()) {
            slidingPaneLayout.openPane();
            onPanelOpened(null);
        }   
    }
    if (slidingPaneLayout.isSlideable()) Log.d(TAG, "isSlideable");

But slidingPaneLayout.isSlideable() always returns false. I tried to run the app on phone and on emulator (Nexus 7), but it always returns the same result. In debug mode mCanSlide variable (of slidingPaneLayout object) is always false.

May anybody tell me what am i doing wrong? Thanks.

Kiryl Tkach
  • 3,118
  • 5
  • 20
  • 36
  • 3
    I think you are calling .isSlideable method too soon. Try using viewtreeobserver for checking if the layout pass is complete and apply the method – Illegal Argument Jul 06 '14 at 14:29

1 Answers1

0

Check

isSlaydeble=false;

slidingPaneLayout = (SlidingPaneLayout) findViewById(R.id.dl_menu);
slidingPaneLayout.setPanelSlideListener(new SlidingPaneLayout.PanelSlideListener() {
            @Override
            public void onPanelSlide(View view, float v) {
                isSlaydeble=true;
            }

            @Override
            public void onPanelOpened(View view) {
            }

            @Override
            public void onPanelClosed(View view) {
            }
        });



<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SlidingPaneLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/dl_menu"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <ListView
            android:id="@+id/lv_menu"
            android:layout_width="240dp"
            android:layout_gravity="left"
            android:layout_height="match_parent"
            android:background="#FFFFFF"
            />

    <FrameLayout
            android:id="@+id/fl_fragment_container"
            android:layout_width="match_parent"
            android:background="#0000FF"
            android:layout_gravity="right"
            android:layout_height="match_parent">
    </FrameLayout>


</android.support.v4.widget.SlidingPaneLayout>
matthias_h
  • 11,356
  • 9
  • 22
  • 40