android 滑动菜单之SlidingMenu

    一,简介:

         SlidingMenu  滑出式菜单(开源),通过拖动屏幕边缘滑出菜单,支持屏幕左右划出,支持菜单zoomscaleslide up三种动画样式出现。
         使用度很高。

          项目地址:https://github.com/jfeinstein10/SlidingMenu
          Demo地址:https://play.google.com/store/apps/details?id=com.slidingmenu.example(估计你访问不了,呵呵)


二,使用步骤:两种集成方式)

       第一种,用libray形式。

          (1) 去下载解压后,把libray导入到工具中,新建 一个android 项目,设置依赖libray.

              

     (2) 在layout下新建一个leftmexu.xml 做为滑出菜单:

       

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:orientation="vertical"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.qiubai.slidemenu.MainActivity$PlaceholderFragment" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="AAAAA" />
    <TextView
        android:id="@+id/bbbb"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="BBBBB" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CCCCCCC" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="EEEEEE" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="FFFFFFF" />

</LinearLayout>
  

   (3)在mainActivity中就可以用了

      

package com.qiubai.slidemenu;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;

public class MainActivity extends Activity {

	TextView bbb;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		// configure the SlidingMenu
       SlidingMenu menu = new SlidingMenu(this);  
       menu.setMode(SlidingMenu.LEFT);  //菜单从哪边出来
      
       menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN); // 设置触摸屏幕的模式 ,设置滑动的屏幕局限,该设置为全屏区域都可以滑动 
       menu.setShadowWidthRes(R.dimen.shadow_width);  //中间阴影宽度
       menu.setShadowDrawable(R.drawable.ic_launcher); //中间阴影的背景
       
       menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);  // 设置滑动菜单视图余下的宽度,SlidingMenu划出时主页面显示的剩余宽度  
       //menu.setBehindWidth(300);//设置SlidingMenu菜单的宽度
       
       menu.setFadeDegree(0.35f); SlidingMenu滑动时的渐变程度 
       menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT); //使SlidingMenu附加在Activity上  
       menu.setMenu(R.layout.leftmenu);   //设置menu的布局文件    //为侧滑菜单设置布局  

       
       menu.toggle();//动态断定主动封闭或开启SlidingMenu
       menu.showMenu();//显示SlidingMenu
       menu.showContent();//显示内容
      
       // menu.setOnOpenListener(onOpenListener);//slidingmenu打开

       // 关于封闭menu有两个,简单的来说,对于menu close事务,一个是when,一个是after 
       //menu.OnClosedListener(OnClosedListener);//slidingmenu封闭时事务
       //menu.OnClosedListener(OnClosedListener);//slidingmenu封闭后事务
       
       //菜单控件按原来处理
       bbb=(TextView) findViewById(R.id.bbbb);
	   bbb.setOnClickListener(new View.OnClickListener() {
		
		@Override
		public void onClick(View v) {
            Toast.makeText(getApplicationContext(), "bbbb", 1).show();
		}
	});
	}

}
  

   其中有两个参数在values文件夹下的dimens.xml

      

    
        <dimen name="shadow_width">0dp</dimen>
        <dimen name="slidingmenu_offset">150dp</dimen>

第二种使用方式

   把libray代码复制到自己的项目中

    



如下:



其他就不说了,附上demo源码下载地址:http://download.csdn.net/detail/gudu1289/9273745

github 源码:http://download.csdn.net/my/uploads

有问题多多指教可加qq:112383348

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值