GridLayout是4.0新增的网格布局,而我们的项目适用最低的版本是2.2,这时如果要使用gridLayout就要使用support-v7包
并不是直接在项目中加入support-v7的jar包,要导入sdk目录下的extra/support/v7/gridlayout下的libs里的项目。
1 在SDK目录下的 \extras\android\support\v7下有 gridlayout 项目,是个library项目, 导入eclipse 稍微调试一下,就不报错了(附件就是)
注意是导入项目!!!!!
如果导入的项目中有红色感叹号,则到
target name那里打钩
2 在自己的项目上右键-->属性-->android-->library里面添加上面的项目
3 按照下面的demo使用就可以啦
在layout文件中使用gridlayout的时候,要这样使用
<span style="font-size:18px;"><android.support.v7.widget.GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/org.javatribe.courseSystem"
android:layout_marginLeft="5dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:rowCount="13"
app:columnCount="6"
android:id="@+id/fmc_gl_course">
</span>
有很多关于gridlayout的属性都改为以app为前缀,而且要加上
<span style="font-size:18px;">xmlns:app="http://schemas.android.com/apk/res/org.javatribe.courseSystem"
这样程序就会去R文件中找这些属性了。
</span>
gridlayout向后兼容的问题可以推及到很多其他ui新特性兼容的问题,只要有支持库,就都可以解决。