• 开源控件slidingmenu的使用


    在github.com网站搜索slidingmenu后https://github.com/jfeinstein10/SlidingMenu

    下载demo,导入library到你的项目中,添加到你项目的依赖中使用:

    package com.loaderman.slidingmenudemo;
    
    import android.app.Activity;
    import android.os.Bundle;
    
    import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
    
    public class MainActivity extends Activity {
    
        @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.shadow);
    
            // 设置滑动菜单视图的宽度
            menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
            // 设置渐入渐出效果的值
            menu.setFadeDegree(0.35f);
            /**
             * SLIDING_WINDOW will include the Title/ActionBar in the content
             * section of the SlidingMenu, while SLIDING_CONTENT does not.
             */
            //把滑动菜单添加进所有的Activity中,可选值SLIDING_CONTENT , SLIDING_WINDOW
            menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
            //为侧滑菜单设置布局
            menu.setMenu(R.layout.leftmenu);
        }
    }
    

     activity_main.xml

    <RelativeLayout
        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:paddingTop="@dimen/activity_vertical_margin"
        tools:context=".MainActivity">
    
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="主界面"
            />
    
    </RelativeLayout>
    

     drawable下创建shadow.xml

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >
    
        <gradient
            android:endColor="#33000000"
            android:centerColor="#11000000"
            android:startColor="#00000000" />
    
    </shape>
    

     侧边栏布局leftmenu.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    
        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="Hello Sliding Menu!" />
    
    </LinearLayout>
    

    dimens.xml

       <dimen name="slidingmenu_offset">80dp</dimen>
        <dimen name="shadow_width">15dp</dimen>
    

     实现效果:

  • 相关阅读:
    PHP四种基础算法详解
    Webuploader教程(一)------简单实用上传功能
    macOS Sierra上面的php开发环境安装
    mac lamp环境 apache文件配置
    mysql 通过拷贝data文件夹进行恢复。
    mysql 执行 cannot found mac安装mysql的两种方法(含配置)
    mac 终端里进入mysql和退出
    macOS Sierra安装Apache2.4+PHP7.0+MySQL5.7.16
    Javascript基础知识
    2016年6月份基础学习要求
  • 原文地址:https://www.cnblogs.com/loaderman/p/6544039.html
Copyright © 2020-2023  润新知