Android GridLayout V7 的支持

January 5, 2013

Android

Android4.0增加了一个 GridLayout , 对于4.0之前的版本,如果要使用 GridLayout ,可以使用 google 提供的android.support.v7.widget.GridLayout , 这是一个项目,在你的 sdk 目录下 sdk_folder\extras\android\compatibility\v7\gridlayout

Library Project including GridLayout.

This can be used by an Android project to provide access to GridLayout on applications running on API 7+ .
按我的理解,这个可以被当成一个Android project使用,用来为API 7 以上的版本提供GridLayout的支持。

There is technically no source, but the src folder is necessary to ensure that the build system works. The content is actually located in libs/android-support-v7-gridlayout.jar .
项目的src目录是空的,但是是必须的,不然会运行不起来。真正的代码被放在了libs下的jar包里了。

USAGE:

Make sure you use <android.support.v7.widget.gridlayout> in your layouts instead of <gridlayout>. Same for <android.support.v7.widget.space> instead of <space>. <android.support.v7.widget.gridlayout>而不是<gridlayout>。

Additionally, all of GridLayout's attributes should be put in the namespace of the app, as those attributes have been redefined in the library so that it can run on older platforms that don't offer those attributes in their namespace.
要注意命名空间的问题。例子里有,注意看readme.txt

To know which attributes need the application namespace, look at the two declare-styleable declared in res/values/attrs.xml
哪些参数可以使用,参考res/values/attrs.xml

总的来说,到目前为止的所有试验的结果是,这个只能当成项目,导入到你的workspace里,导入后,这个项目默认是一个library项目,可以看项目下的project.properties文件,里面有这么几行:

# Project target.
target=android-7
android.library=true

然后再你想使用GridLayout的项目里,引入这个项目作为库。 具体步骤参考http://developer.android.com/tools/projects/projects-eclipse.html 有图有真相有英文。

我尝试把这个GridLayout当成一个jar包导入到我的项目里,到目前为止是没有成功的。在网上找到GridLayout的源码,但是不是全部的。

--- EOF ---

添加新评论