在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

相关文章

Spring中@Lazy注解的使用技巧与实例解析

《Spring中@Lazy注解的使用技巧与实例解析》@Lazy注解在Spring框架中用于延迟Bean的初始化,优化应用启动性能,它不仅适用于@Bean和@Component,还可以用于注入点,通过将... 目录一、@Lazy注解的作用(一)延迟Bean的初始化(二)与@Autowired结合使用二、实例解

SpringBoot使用Jasypt对YML文件配置内容加密的方法(数据库密码加密)

《SpringBoot使用Jasypt对YML文件配置内容加密的方法(数据库密码加密)》本文介绍了如何在SpringBoot项目中使用Jasypt对application.yml文件中的敏感信息(如数... 目录SpringBoot使用Jasypt对YML文件配置内容进行加密(例:数据库密码加密)前言一、J

Spring Boot 中正确地在异步线程中使用 HttpServletRequest的方法

《SpringBoot中正确地在异步线程中使用HttpServletRequest的方法》文章讨论了在SpringBoot中如何在异步线程中正确使用HttpServletRequest的问题,... 目录前言一、问题的来源:为什么异步线程中无法访问 HttpServletRequest?1. 请求上下文与线

在 Spring Boot 中使用异步线程时的 HttpServletRequest 复用问题记录

《在SpringBoot中使用异步线程时的HttpServletRequest复用问题记录》文章讨论了在SpringBoot中使用异步线程时,由于HttpServletRequest复用导致... 目录一、问题描述:异步线程操作导致请求复用时 Cookie 解析失败1. 场景背景2. 问题根源二、问题详细分

从零教你安装pytorch并在pycharm中使用

《从零教你安装pytorch并在pycharm中使用》本文详细介绍了如何使用Anaconda包管理工具创建虚拟环境,并安装CUDA加速平台和PyTorch库,同时在PyCharm中配置和使用PyTor... 目录背景介绍安装Anaconda安装CUDA安装pytorch报错解决——fbgemm.dll连接p

Vue项目的甘特图组件之dhtmlx-gantt使用教程和实现效果展示(推荐)

《Vue项目的甘特图组件之dhtmlx-gantt使用教程和实现效果展示(推荐)》文章介绍了如何使用dhtmlx-gantt组件来实现公司的甘特图需求,并提供了一个简单的Vue组件示例,文章还分享了一... 目录一、首先 npm 安装插件二、创建一个vue组件三、业务页面内 引用自定义组件:四、dhtmlx

使用Python创建一个能够筛选文件的PDF合并工具

《使用Python创建一个能够筛选文件的PDF合并工具》这篇文章主要为大家详细介绍了如何使用Python创建一个能够筛选文件的PDF合并工具,文中的示例代码讲解详细,感兴趣的小伙伴可以了解下... 目录背景主要功能全部代码代码解析1. 初始化 wx.Frame 窗口2. 创建工具栏3. 创建布局和界面控件4

一文详解如何在Python中使用Requests库

《一文详解如何在Python中使用Requests库》:本文主要介绍如何在Python中使用Requests库的相关资料,Requests库是Python中常用的第三方库,用于简化HTTP请求的发... 目录前言1. 安装Requests库2. 发起GET请求3. 发送带有查询参数的GET请求4. 发起PO

Java中的Cursor使用详解

《Java中的Cursor使用详解》本文介绍了Java中的Cursor接口及其在大数据集处理中的优势,包括逐行读取、分页处理、流控制、动态改变查询、并发控制和减少网络流量等,感兴趣的朋友一起看看吧... 最近看代码,有一段代码涉及到Cursor,感觉写法挺有意思的。注意是Cursor,而不是Consumer

Node.js net模块的使用示例

《Node.jsnet模块的使用示例》本文主要介绍了Node.jsnet模块的使用示例,net模块支持TCP通信,处理TCP连接和数据传输,具有一定的参考价值,感兴趣的可以了解一下... 目录简介引入 net 模块核心概念TCP (传输控制协议)Socket服务器TCP 服务器创建基本服务器服务器配置选项服