在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

相关文章

使用Java将DOCX文档解析为Markdown文档的代码实现

《使用Java将DOCX文档解析为Markdown文档的代码实现》在现代文档处理中,Markdown(MD)因其简洁的语法和良好的可读性,逐渐成为开发者、技术写作者和内容创作者的首选格式,然而,许多文... 目录引言1. 工具和库介绍2. 安装依赖库3. 使用Apache POI解析DOCX文档4. 将解析

Qt中QUndoView控件的具体使用

《Qt中QUndoView控件的具体使用》QUndoView是Qt框架中用于可视化显示QUndoStack内容的控件,本文主要介绍了Qt中QUndoView控件的具体使用,具有一定的参考价值,感兴趣的... 目录引言一、QUndoView 的用途二、工作原理三、 如何与 QUnDOStack 配合使用四、自

C++使用printf语句实现进制转换的示例代码

《C++使用printf语句实现进制转换的示例代码》在C语言中,printf函数可以直接实现部分进制转换功能,通过格式说明符(formatspecifier)快速输出不同进制的数值,下面给大家分享C+... 目录一、printf 原生支持的进制转换1. 十进制、八进制、十六进制转换2. 显示进制前缀3. 指

如何解决idea的Module:‘:app‘platform‘android-32‘not found.问题

《如何解决idea的Module:‘:app‘platform‘android-32‘notfound.问题》:本文主要介绍如何解决idea的Module:‘:app‘platform‘andr... 目录idea的Module:‘:app‘pwww.chinasem.cnlatform‘android-32

使用Python构建一个Hexo博客发布工具

《使用Python构建一个Hexo博客发布工具》虽然Hexo的命令行工具非常强大,但对于日常的博客撰写和发布过程,我总觉得缺少一个直观的图形界面来简化操作,下面我们就来看看如何使用Python构建一个... 目录引言Hexo博客系统简介设计需求技术选择代码实现主框架界面设计核心功能实现1. 发布文章2. 加

Node.js 数据库 CRUD 项目示例详解(完美解决方案)

《Node.js数据库CRUD项目示例详解(完美解决方案)》:本文主要介绍Node.js数据库CRUD项目示例详解(完美解决方案),本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考... 目录项目结构1. 初始化项目2. 配置数据库连接 (config/db.js)3. 创建模型 (models/

shell编程之函数与数组的使用详解

《shell编程之函数与数组的使用详解》:本文主要介绍shell编程之函数与数组的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录shell函数函数的用法俩个数求和系统资源监控并报警函数函数变量的作用范围函数的参数递归函数shell数组获取数组的长度读取某下的

使用Python开发一个带EPUB转换功能的Markdown编辑器

《使用Python开发一个带EPUB转换功能的Markdown编辑器》Markdown因其简单易用和强大的格式支持,成为了写作者、开发者及内容创作者的首选格式,本文将通过Python开发一个Markd... 目录应用概览代码结构与核心组件1. 初始化与布局 (__init__)2. 工具栏 (setup_t

springboot项目中常用的工具类和api详解

《springboot项目中常用的工具类和api详解》在SpringBoot项目中,开发者通常会依赖一些工具类和API来简化开发、提高效率,以下是一些常用的工具类及其典型应用场景,涵盖Spring原生... 目录1. Spring Framework 自带工具类(1) StringUtils(2) Coll

Python虚拟环境终极(含PyCharm的使用教程)

《Python虚拟环境终极(含PyCharm的使用教程)》:本文主要介绍Python虚拟环境终极(含PyCharm的使用教程),具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,... 目录一、为什么需要虚拟环境?二、虚拟环境创建方式对比三、命令行创建虚拟环境(venv)3.1 基础命令3