在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.SlidingMenu
    xmlns: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.SlidingMenu
    xmlns: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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值