support.v4之SlidingPaneLayout简单使用

简单的布局

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

    <!-- Left side pane. (Master) -->
    <FrameLayout
        android:id="@+id/leftpane"
        android:layout_width="100dp"
        android:layout_height="match_parent"
        android:layout_gravity="left"
        android:background="@android:color/holo_blue_dark" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:text="Menus" />
    </FrameLayout>

    <FrameLayout
        android:id="@+id/rightpane"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="right"
        android:layout_weight="1"
        android:background="@android:color/white" >

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="Main Content" />
    </FrameLayout>

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

简单的使用

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.widget.SlidingPaneLayout;
import android.util.Log;
import android.view.View;

public class SlidingLeftPanelActivity extends Activity {

	private Context context;

	private SlidingPaneLayout pane;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_sliding_left_panel);
		context = this;
		initViews();
	}

	private void initViews() {
		pane = (SlidingPaneLayout) findViewById(R.id.slidingPaneLayout);
		pane.setPanelSlideListener(new PaneListener());
	}

	private class PaneListener implements SlidingPaneLayout.PanelSlideListener {

		@Override
		public void onPanelClosed(View view) {
			Log.i("tag", "==========onPanelClosed===========");
		}

		@Override
		public void onPanelOpened(View view) {
			Log.i("tag", "==========onPanelOpened===========");
		}

		@Override
		public void onPanelSlide(View view, float arg1) {
			Log.i("tag", "==========onPanelSlide===========");
		}

	}

	@Override
	public void onBackPressed() {
		if (pane.isSlideable() && pane.isOpen()) {
			pane.closePane();
		} else {
			super.onBackPressed();
		}
	}

}

部分可见的侧边菜单与交叉渐变效果的SlidingPaneLayout

http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0208/2435.html

相关推荐