在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

相关文章

这15个Vue指令,让你的项目开发爽到爆

1. V-Hotkey 仓库地址: github.com/Dafrok/v-ho… Demo: 戳这里 https://dafrok.github.io/v-hotkey 安装: npm install --save v-hotkey 这个指令可以给组件绑定一个或多个快捷键。你想要通过按下 Escape 键后隐藏某个组件,按住 Control 和回车键再显示它吗?小菜一碟: <template

中文分词jieba库的使用与实景应用(一)

知识星球:https://articles.zsxq.com/id_fxvgc803qmr2.html 目录 一.定义: 精确模式(默认模式): 全模式: 搜索引擎模式: paddle 模式(基于深度学习的分词模式): 二 自定义词典 三.文本解析   调整词出现的频率 四. 关键词提取 A. 基于TF-IDF算法的关键词提取 B. 基于TextRank算法的关键词提取

使用SecondaryNameNode恢复NameNode的数据

1)需求: NameNode进程挂了并且存储的数据也丢失了,如何恢复NameNode 此种方式恢复的数据可能存在小部分数据的丢失。 2)故障模拟 (1)kill -9 NameNode进程 [lytfly@hadoop102 current]$ kill -9 19886 (2)删除NameNode存储的数据(/opt/module/hadoop-3.1.4/data/tmp/dfs/na

Hadoop数据压缩使用介绍

一、压缩原则 (1)运算密集型的Job,少用压缩 (2)IO密集型的Job,多用压缩 二、压缩算法比较 三、压缩位置选择 四、压缩参数配置 1)为了支持多种压缩/解压缩算法,Hadoop引入了编码/解码器 2)要在Hadoop中启用压缩,可以配置如下参数

Makefile简明使用教程

文章目录 规则makefile文件的基本语法:加在命令前的特殊符号:.PHONY伪目标: Makefilev1 直观写法v2 加上中间过程v3 伪目标v4 变量 make 选项-f-n-C Make 是一种流行的构建工具,常用于将源代码转换成可执行文件或者其他形式的输出文件(如库文件、文档等)。Make 可以自动化地执行编译、链接等一系列操作。 规则 makefile文件

如何用Docker运行Django项目

本章教程,介绍如何用Docker创建一个Django,并运行能够访问。 一、拉取镜像 这里我们使用python3.11版本的docker镜像 docker pull python:3.11 二、运行容器 这里我们将容器内部的8080端口,映射到宿主机的80端口上。 docker run -itd --name python311 -p

使用opencv优化图片(画面变清晰)

文章目录 需求影响照片清晰度的因素 实现降噪测试代码 锐化空间锐化Unsharp Masking频率域锐化对比测试 对比度增强常用算法对比测试 需求 对图像进行优化,使其看起来更清晰,同时保持尺寸不变,通常涉及到图像处理技术如锐化、降噪、对比度增强等 影响照片清晰度的因素 影响照片清晰度的因素有很多,主要可以从以下几个方面来分析 1. 拍摄设备 相机传感器:相机传

【Python编程】Linux创建虚拟环境并配置与notebook相连接

1.创建 使用 venv 创建虚拟环境。例如,在当前目录下创建一个名为 myenv 的虚拟环境: python3 -m venv myenv 2.激活 激活虚拟环境使其成为当前终端会话的活动环境。运行: source myenv/bin/activate 3.与notebook连接 在虚拟环境中,使用 pip 安装 Jupyter 和 ipykernel: pip instal

Android实现任意版本设置默认的锁屏壁纸和桌面壁纸(两张壁纸可不一致)

客户有些需求需要设置默认壁纸和锁屏壁纸  在默认情况下 这两个壁纸是相同的  如果需要默认的锁屏壁纸和桌面壁纸不一样 需要额外修改 Android13实现 替换默认桌面壁纸: 将图片文件替换frameworks/base/core/res/res/drawable-nodpi/default_wallpaper.*  (注意不能是bmp格式) 替换默认锁屏壁纸: 将图片资源放入vendo

pdfmake生成pdf的使用

实际项目中有时会有根据填写的表单数据或者其他格式的数据,将数据自动填充到pdf文件中根据固定模板生成pdf文件的需求 文章目录 利用pdfmake生成pdf文件1.下载安装pdfmake第三方包2.封装生成pdf文件的共用配置3.生成pdf文件的文件模板内容4.调用方法生成pdf 利用pdfmake生成pdf文件 1.下载安装pdfmake第三方包 npm i pdfma