如何在eclipse使用StaggeredGridView

 

概述 

现在的开发工具基本都用AndroidStudio了。网上的开源框架也是。比如做瀑布式UI的StaggeredGridView,还有导航页的PagerSlidingTabStrip等。 

那么电脑性能不好的,还在用eclipse怎么使用这些开源框架呢?

步骤

准备工作

下载对应的框架如StaggeredGridView在https://github.com/etsy/AndroidStaggeredGrid。

解压完。需要的资源是在:StaggeredGridView-master\src\com\origamilabs\library\views下的三个java文件;

StaggeredGridView-master\res\values的attrs.xml

步骤:

 1.打开StaggeredGridView下的AndroidManifest.xml,把其中的 android:allowBackup="true" 复制到你的工程对应位置

 2. 如果你的工程res/values下没有attrs.xml,那么把在StaggeredGridView中的这个直接粘贴在你的这个文件夹下。如果你已经存在有

了这个文件,那么把其中的代码复制到你的attrs.xml中。

 

    declare-styleable name="StaggeredGridView">
        <attr name="column_count" format="integer" />
        <attr name="column_count_portrait" format="integer" />
        <attr name="column_count_landscape" format="integer" />
        <attr name="item_margin" format="dimension" />
        <attr name="grid_paddingLeft" format="dimension" />
        <attr name="grid_paddingRight" format="dimension" />
        <attr name="grid_paddingTop" format="dimension" />
        <attr name="grid_paddingBottom" format="dimension" />
    </declare-styleable>

 

 

 

3.把准备那里的那个java文件复制到你的工程中(注意一点,这三个文件复制到和你的AndroidManifest.xml相同包名的包中, 不然在定义view配置xml的时候会提示找不到资源)该包名,添加自己包.R文件。就没错了

4.最后就可以在布局文件中使用了。添加的时候也是要把包名带上。可以直接右键蓝色选中的文件,然后点击Copy Qualified name.完整名字就复制好了。

比如我的是

<com.Mihai.text.StaggeredGridView
            android:id="@+id/stagger_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:itemMargin="8dp"
            app:numColumns="2"
            >
            
        </com.Mihai.text.StaggeredGridView>

 

后记

一开始学android,不要被框架这词迷惑了,只要把它所有相关代码复制到我们的工程就可以用了,包括配置文件,自定义属性等。当然会有错误,常见的就是包名还有xxx.R文件错误,只要导入自己的就可以了。还有的就是android.support.v4.jar包的错误,提示import xxx 错误。可能是版本不对因为v4支持包也是有不同版本的用最新的就好了。

 

posted @ 2016-08-26 21:15  Mihai  阅读(568)  评论(0编辑  收藏  举报