当前位置: 首页 > 工具软件 > cardslib > 使用案例 >

Android项目笔记【项目管理统计图app】:使用github上的cardslib开源项目实现CardView(1)...

臧增
2023-12-01

因为项目中用到第三级菜单,我们原有的界面框架已经不适用于该项目,Android L出了新的cardview设计,爬了下github发现有些高手已经把card整合为更方便调用的类库了,我这个项目就准备试用一下其中的一个开源项目cardslib      , 而github我也是初次使用,正好在项目中来熟悉使用方法

首先:

  cardslib项目地址:https://github.com/gabrielemariotti/cardslib,意大利的一位java/android工程师gabrielemariotti,基于Android L 的cardview做的一个便于引用和扩展的卡片式布局,可以fork一下到自己的代码仓库。

  我的项目中主要用到其中的library-corelibrary-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

 类似资料: