Android项目笔记【项目管理统计图app】:使用github上的cardslib开源项目实现CardView(1)...
因為項目中用到第三級菜單,我們原有的界面框架已經不適用于該項目,Android L出了新的cardview設計,爬了下github發現有些高手已經把card整合為更方便調用的類庫了,我這個項目就準備試用一下其中的一個開源項目cardslib ? ? ?, 而github我也是初次使用,正好在項目中來熟悉使用方法
首先:
cardslib項目地址:https://github.com/gabrielemariotti/cardslib,意大利的一位java/android工程師gabrielemariotti,基于Android L 的cardview做的一個便于引用和擴展的卡片式布局,可以fork一下到自己的代碼倉庫。
我的項目中主要用到其中的library-core和library-cards,以下為作者提供的eclipse中引入該項目為類庫的方法(不得不說國外開發牛實在是太貼心了T_T,文檔寫得盡善盡美,我這種初級菜鳥也能按部就班的實現):
Reference this project as a library in Eclipse
If you would like to use this?library-core?in Eclipse you have to do these steps:
- clone a copy of this repository, or download it (outside eclipse workspace)
- import the code in your workspace starting from library folder. The Wizard will import the code in library-core/src/main. I suggest you naming it "cardscore" (or another name) instead of "main".
- mark java(*) folder as source (click on folder -> Build-Path -> use as source folder). You can also remove the src folder, from the project.
- mark cardscore as Android Library (Properties -> Android -> Is library)
- add support library v4 rel.21
- add support cardview library v7 rel.21
- add support annotation library rel.21
- The library targets SDK 21 and works with minSdk=14. In any cases you need to use API>=21 to compile library (Properties -> Android)
- Clean and build
If you would like to use this?library-cards?in Eclipse you have to do these steps:
- clone a copy of this repository, or download it (outside eclipse workspace)
- import the code in your workspace starting from library folder. The Wizard will import the code in library-cards/src/main. I suggest you naming it "cardscore" (or another name) instead of "main".
- mark java(*) folder as source (click on folder -> Build-Path -> use as source folder). You can also remove the src folder, from the project.
- mark cardscore as Android Library (Properties -> Android -> Is library)
- add the cardscore as library
- The library targets SDK 21 and works with minSdk=14. In any cases you need to use API>=21 to compile library (Properties -> Android)
- Clean and build
注意要點:
1、需要anroid 21的SDK支持
2、把引用代碼的main文件夾重命名,并右鍵build-path該文件夾為"use as source folder",否則可能會造成代碼沖突
3、將工程作為Android Libaray,引入相應support ?library
引用后,在build時和編譯時分別出過一個問題:
1、build后,報錯,Found 4 versions of android-support-v4.jar in the dependency list
查看了報錯信息是因為之前引用的滑動菜單的幾個library中,android-support-v4的版本和cardslib中所用版本不同。拷cardslib中的v4過去就行了
2、運行時報錯,2 Output: UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files?define?Landroid/support/annotation/AnimRes;
?應該是導入的包和以前的導入有沖突,解決辦法簡單粗暴:我把我的項目中libs文件夾下的包全部拷出來,然后重建這個文件夾,手動一個個拷進去檢查,直到0 error為止(可能有些運行時要用的包沒有拷到,以后運行時報錯的時候再根據提示單獨拷就可以了:)最后在stackoverflow找到原因,引用的library-core庫中,新版本的support-v4包已經包含了support-annotations的內容,刪去annotations包即可:
The problem is that?android-support-annotations.jar?used to be a separate library containing the android annotations, but for some reason these annotations are already included in recent versions of the?android-support-v4.jar?file.
轉載于:https://www.cnblogs.com/melonrice/p/4103997.html
總結
以上是生活随笔為你收集整理的Android项目笔记【项目管理统计图app】:使用github上的cardslib开源项目实现CardView(1)...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 爱摘苹果的小明
- 下一篇: Android开源之行之走进zxing,