在Android studio中使用SlidingMenu创建项目

2024-06-17 10:08

本文主要是介绍在Android studio中使用SlidingMenu创建项目,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

在看前一篇从大神那里转来的日志时,我很快就在eclipse中验证出来了,可是由于是刚刚开始使用Android Stuido,很多地方都是摸索。在网上看到一些方法,可是测试出了问题,问题不在别人那里,在自己这里,了解甚少,好在自己摸索出来了方法,记录在此。


首先在AS中直接新建了一个项目,我这里用的AS是o0.8Beta版,首先我去github上下载了SlidingMenu的相关文件,下载地址:https://github.com/jfeinstein10/SlidingMenu。


我通过Improt Moudle的方式将SlidingMenu源码中的library导入作为Moudle,然后出现了下面的问题:


出现这个问题的原因是:

我们导入的library文件夹中的build.gradle 文件里面写的很清楚:

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

}它需要的build工具版本是17我这里没装,所以出问题了,解决方法:

一 、 直接打开SDK Manager去下载build tools 17版本;

二 、 我们把这个配置文件改成和我们当前项目一样的版本就OK了。


第二种方法简单粗暴一步到位,第一种方法可能会出现问题:

Error:The SDK Build Tools revision (17.0.0) is too low for project ':library'. Minimum required is 19.1.0
这是什么玩意,我找了很久都没找到19.1.0写在了哪里,后来查资料发现这玩意跟

dependencies {
        classpath 'com.android.tools.build:gradle:0.4.+'
    }

有关。你会发现AS会有提示:

you have to use a newer version of the Android Gradle plugin......后面告诉你当前最低支持的是什么,然后直接改成最低支持的就行了。我这里最小支持的是19.1.0,修改成

'com.android.tools.build:gradle:0.12.+'但是你这里改了之后就相当于告诉人家最小也得19.1.0,所以你还是得改

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

}比如,我改成了 buildToolsVersion "19.1.0"。就不会出错了。

到这里我们算是把这个工程文件导入了,接下来,由于我们需要用到它作为一个依赖项目,所以,我们需要他们两个有点联系,如果在eclipse里就不说了,这里怎么办么,很简单。直接说快捷键吧,Shift Ctrl Alt S ,弹出一个界面:



选中App就是你自己的项目,下面那个library就是我们刚才导入的项目,我们选择最右边的“+”然后会出现1、2、3三个选项,简单了解了下,选择第一个的话就是选择一些AS提供的一些类库,你可以在AS中去下载添加啥的,反正我没用;第二个呢,比如你从外面复制了一个.jar文件到你的项目的某个文件里,比如libs文件夹里,点这个相当于eclipse里面给它build path;第三个,看名字都懂了,咱们要用的就是第三个,怎么操作,点开了自然知晓。


加完之后我们进入项目中试试,SplidingMenu能用了不,OK,搞定啦。



附录,SlidingMenu作为控件时候的一些属性:



XML Usage

If you decide to use SlidingMenu as a view, you can define it in your xml layouts like this:

<com.jeremyfeinstein.slidingmenu.lib.SlidingMenuxmlns:sliding="http://schemas.android.com/apk/res-auto"android:id="@+id/slidingmenulayout"android:layout_width="fill_parent"android:layout_height="fill_parent"sliding:viewAbove="@layout/YOUR_ABOVE_VIEW"sliding:viewBehind="@layout/YOUR_BEHIND_BEHIND"sliding:touchModeAbove="margin|fullscreen"sliding:behindOffset="@dimen/YOUR_OFFSET"sliding:behindWidth="@dimen/YOUR_WIDTH"sliding:behindScrollScale="@dimen/YOUR_SCALE"sliding:shadowDrawable="@drawable/YOUR_SHADOW"sliding:shadowWidth="@dimen/YOUR_SHADOW_WIDTH"sliding:fadeEnabled="true|false"sliding:fadeDegree="float"sliding:selectorEnabled="true|false"sliding:selectorDrawable="@drawable/YOUR_SELECTOR"/>

NOTE : you cannot use both behindOffset and behindWidth. You will get an exception if you try.

  • viewAbove - a reference to the layout that you want to use as the above view of the SlidingMenu
  • viewBehind - a reference to the layout that you want to use as the behind view of the SlidingMenu
  • touchModeAbove - an enum that designates what part of the screen is touchable when the above view is showing. Margin means only the left margin. Fullscreen means the entire screen. Default is margin.
  • behindOffset - a dimension representing the number of pixels that you want the above view to show when the behind view is showing. Default is 0.
  • behindWidth - a dimension representing the width of the behind view. Default is the width of the screen (equivalent to behindOffset = 0).
  • behindScrollScale - a float representing the relationship between the above view scrolling and the behind behind view scrolling. If set to 0.5f, the behind view will scroll 1px for every 2px that the above view scrolls. If set to 1.0f, the behind view will scroll 1px for every 1px that the above view scrolls. And if set to 0.0f, the behind view will never scroll; it will be static. This one is fun to play around with. Default is 0.25f.
  • shadowDrawable - a reference to a drawable to be used as a drop shadow from the above view onto the below view. Default is no shadow for now.
  • shadowWidth - a dimension representing the width of the shadow drawable. Default is 0.
  • fadeEnabled - a boolean representing whether or not the behind view should fade when the SlidingMenu is closing and "un-fade" when opening
  • fadeDegree - a float representing the "amount" of fade. 1.0f would mean fade all the way to black when the SlidingMenu is closed. 0.0f would mean do not fade at all.
  • selectorEnabled - a boolean representing whether or not a selector should be drawn on the left side of the above view showing a selected view on the behind view.
  • selectorDrawable - a reference to a drawable to be used as the selector NOTE : in order to have the selector drawn, you must call SlidingMenu.setSelectedView(View v) with the selected view. Note that this will most likely not work with items in a ListView because of the way that Android recycles item views.

XML Usage

If you decide to use SlidingMenu as a view, you can define it in your xml layouts like this:

<com.jeremyfeinstein.slidingmenu.lib.SlidingMenuxmlns:sliding="http://schemas.android.com/apk/res-auto"android:id="@+id/slidingmenulayout"android:layout_width="fill_parent"android:layout_height="fill_parent"sliding:viewAbove="@layout/YOUR_ABOVE_VIEW"sliding:viewBehind="@layout/YOUR_BEHIND_BEHIND"sliding:touchModeAbove="margin|fullscreen"sliding:behindOffset="@dimen/YOUR_OFFSET"sliding:behindWidth="@dimen/YOUR_WIDTH"sliding:behindScrollScale="@dimen/YOUR_SCALE"sliding:shadowDrawable="@drawable/YOUR_SHADOW"sliding:shadowWidth="@dimen/YOUR_SHADOW_WIDTH"sliding:fadeEnabled="true|false"sliding:fadeDegree="float"sliding:selectorEnabled="true|false"sliding:selectorDrawable="@drawable/YOUR_SELECTOR"/>

NOTE : you cannot use both behindOffset and behindWidth. You will get an exception if you try.

  • viewAbove - a reference to the layout that you want to use as the above view of the SlidingMenu
  • viewBehind - a reference to the layout that you want to use as the behind view of the SlidingMenu
  • touchModeAbove - an enum that designates what part of the screen is touchable when the above view is showing. Margin means only the left margin. Fullscreen means the entire screen. Default is margin.
  • behindOffset - a dimension representing the number of pixels that you want the above view to show when the behind view is showing. Default is 0.
  • behindWidth - a dimension representing the width of the behind view. Default is the width of the screen (equivalent to behindOffset = 0).
  • behindScrollScale - a float representing the relationship between the above view scrolling and the behind behind view scrolling. If set to 0.5f, the behind view will scroll 1px for every 2px that the above view scrolls. If set to 1.0f, the behind view will scroll 1px for every 1px that the above view scrolls. And if set to 0.0f, the behind view will never scroll; it will be static. This one is fun to play around with. Default is 0.25f.
  • shadowDrawable - a reference to a drawable to be used as a drop shadow from the above view onto the below view. Default is no shadow for now.
  • shadowWidth - a dimension representing the width of the shadow drawable. Default is 0.
  • fadeEnabled - a boolean representing whether or not the behind view should fade when the SlidingMenu is closing and "un-fade" when opening
  • fadeDegree - a float representing the "amount" of fade. 1.0f would mean fade all the way to black when the SlidingMenu is closed. 0.0f would mean do not fade at all.
  • selectorEnabled - a boolean representing whether or not a selector should be drawn on the left side of the above view showing a selected view on the behind view.
  • selectorDrawable - a reference to a drawable to be used as the selector NOTE : in order to have the selector drawn, you must call SlidingMenu.setSelectedView(View v) with the selected view. Note that this will most likely not work with items in a ListView because of the way that Android recycles item views.

这篇关于在Android studio中使用SlidingMenu创建项目的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!


原文地址:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.chinasem.cn/article/1069149

相关文章

使用Python获取JS加载的数据的多种实现方法

《使用Python获取JS加载的数据的多种实现方法》在当今的互联网时代,网页数据的动态加载已经成为一种常见的技术手段,许多现代网站通过JavaScript(JS)动态加载内容,这使得传统的静态网页爬取... 目录引言一、动态 网页与js加载数据的原理二、python爬取JS加载数据的方法(一)分析网络请求1

SpringCloud使用Nacos 配置中心实现配置自动刷新功能使用

《SpringCloud使用Nacos配置中心实现配置自动刷新功能使用》SpringCloud项目中使用Nacos作为配置中心可以方便开发及运维人员随时查看配置信息,及配置共享,并且Nacos支持配... 目录前言一、Nacos中集中配置方式?二、使用步骤1.使用$Value 注解2.使用@Configur

Mac备忘录怎么导出/备份和云同步? Mac备忘录使用技巧

《Mac备忘录怎么导出/备份和云同步?Mac备忘录使用技巧》备忘录作为iOS里简单而又不可或缺的一个系统应用,上手容易,可以满足我们日常生活中各种记录的需求,今天我们就来看看Mac备忘录的导出、... 「备忘录」是 MAC 上的一款常用应用,它可以帮助我们捕捉灵感、记录待办事项或保存重要信息。为了便于在不同

如何Python使用设置word的页边距

《如何Python使用设置word的页边距》在编写或处理Word文档的过程中,页边距是一个不可忽视的排版要素,本文将介绍如何使用Python设置Word文档中各个节的页边距,需要的可以参考下... 目录操作步骤代码示例页边距单位说明应用场景与高级用China编程途小结在编写或处理Word文档的过程中,页边距是一个

SpringBoot项目Web拦截器使用的多种方式

《SpringBoot项目Web拦截器使用的多种方式》在SpringBoot应用中,Web拦截器(Interceptor)是一种用于在请求处理的不同阶段执行自定义逻辑的机制,下面给大家介绍Sprin... 目录一、实现 HandlerInterceptor 接口1、创建HandlerInterceptor实

使用JavaConfig配置Spring的流程步骤

《使用JavaConfig配置Spring的流程步骤》JavaConfig是Spring框架提供的一种基于Java的配置方式,它通过使用@Configuration注解标记的类来替代传统的XML配置文... 目录一、什么是 JavaConfig?1. 核心注解2. 与 XML 配置的对比二、JavaConf

Maven项目打包时添加本地Jar包的操作步骤

《Maven项目打包时添加本地Jar包的操作步骤》在Maven项目开发中,我们经常会遇到需要引入本地Jar包的场景,比如使用未发布到中央仓库的第三方库或者处理版本冲突的依赖项,本文将详细介绍如何通过M... 目录一、适用场景说明​二、核心操作命令​1. 命令格式解析​2. 实战案例演示​三、项目配置步骤​1

使用Python和Tkinter实现html标签去除工具

《使用Python和Tkinter实现html标签去除工具》本文介绍用Python和Tkinter开发的HTML标签去除工具,支持去除HTML标签、转义实体并输出纯文本,提供图形界面操作及复制功能,需... 目录html 标签去除工具功能介绍创作过程1. 技术选型2. 核心实现逻辑3. 用户体验增强如何运行

Go语言中使用JWT进行身份验证的几种方式

《Go语言中使用JWT进行身份验证的几种方式》本文主要介绍了Go语言中使用JWT进行身份验证的几种方式,包括dgrijalva/jwt-go、golang-jwt/jwt、lestrrat-go/jw... 目录简介1. github.com/dgrijalva/jwt-go安装:使用示例:解释:2. gi

Python使用python-docx实现自动化处理Word文档

《Python使用python-docx实现自动化处理Word文档》这篇文章主要为大家展示了Python如何通过代码实现段落样式复制,HTML表格转Word表格以及动态生成可定制化模板的功能,感兴趣的... 目录一、引言二、核心功能模块解析1. 段落样式与图片复制2. html表格转Word表格3. 模板生