http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 2431|回复: 4

[新手开发之旅] Android新手开发之旅-使用SlidingMeau实现侧滑菜单

[复制链接]
发表于 2018-12-20 13:20:28 | 显示全部楼层 |阅读模式
使用SlidingMeau实现侧滑菜单




SlidingMeau是一个第三方开源库,使用它能快速的帮我们实现侧滑菜单


步骤:


1、下载地址:https://github.com/jfeinstein10/SlidingMenu

         QQ截图20181218091426.png


2、将下载好的文件解压,找到library文件夹,将他导入到Android Studio



         QQ截图20181218091558.png
       QQ截图20181218091828.png

3、导入后可能会报错,我们需要把它的build.gradle文件修改:
     dependencies的classpath改为你项目根目录的build.gradle的dependencies的classpath
     compileSdkVerSion和buildToolsVersion和targetSdkVersion改成和你app目录下的build.gradle里面一致就可以了
     apply plugin: 'android-library'修改为apply plugin: 'com.android.library'


       QQ截图20181218092809.png

4、给我们的项目添加module依赖:
      
       QQ截图20181218093134.png

         QQ截图20181218093252.png

         QQ截图20181218093642.png

点击完成后就可以在我们的项目中使用SlidingMeau了


5、新建一个布局来显示侧滑菜单
slidingmenu.xml:
[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">

    <com.jeremyfeinstein.slidingmenu.lib.SlidingMenu
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorPrimary"
            android:orientation="vertical">


            <TextView
                android:layout_width="match_parent"
                android:layout_height="45dp"
                android:gravity="center_vertical"
                android:paddingLeft="20dp"
                android:textColor="@android:color/white"
                android:text="第一个选项" />

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@color/colorAccent" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="45dp"
                android:gravity="center_vertical"
                android:paddingLeft="20dp"
                android:textColor="@android:color/white"
                android:text="第二个选项" />

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@color/colorAccent" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="45dp"
                android:gravity="center_vertical"
                android:paddingLeft="20dp"
                android:textColor="@android:color/white"
                android:text="第三个选项" />

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:background="@color/colorAccent" />
        </LinearLayout>
    </com.jeremyfeinstein.slidingmenu.lib.SlidingMenu>
</LinearLayout>

java代码
[Java] 纯文本查看 复制代码
package com.company.helloworld.firstapplication;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;

public class MainActivity extends AppCompatActivity {


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

        SlidingMenu mSlidingMenu = new SlidingMenu(this);
        //设置从左弹出/滑出SlidingMenu
        mSlidingMenu.setMode(SlidingMenu.LEFT);
        //设置占满屏幕
        mSlidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
        //绑定到哪一个Activity对象
        mSlidingMenu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
        //设置弹出的SlidingMenu的布局文件
        mSlidingMenu.setMenu(R.layout.slidingmenu);
        //设置SlidingMenu所占的偏移
        mSlidingMenu.setBehindOffsetRes(R.dimen.slidingmeau);

    }

}

res/value下新建dimen.xml:
[XML] 纯文本查看 复制代码
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <dimen name="slidingmeau">200dp</dimen>
</resources>



看下效果:


         x.gif


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2018-12-20 13:57:37 | 显示全部楼层
我只是路过打酱油的。
发表于 2018-12-20 14:03:29 | 显示全部楼层
我只是路过打酱油的。
发表于 2018-12-20 15:15:47 | 显示全部楼层
激动人心,无法言表!
发表于 2018-12-20 16:41:59 | 显示全部楼层
感恩无私的分享与奉献
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-4-17 00:10

© 2014-2021

快速回复 返回顶部 返回列表