首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从支持库以编程方式创建GridLayout

从支持库以编程方式创建GridLayout
EN

Stack Overflow用户
提问于 2012-08-11 00:03:48
回答 1查看 4.2K关注 0票数 8

在android中,有没有可能完全通过编程方式从支持库创建一个GridLayout (也就是说,不需要编写相应的xml)?

我在片段(名为PromotionLayoutFragment)中创建GridLayout,如下所示:

代码语言:javascript
复制
ViewGroup fragmentView = (ViewGroup)getView(); 
GridLayout gridLayout = new GridLayout(fragmentView.getContext());
gridLayout.setColumnCount(2);
gridLayout.setRowCount(15);
// add views to grid ...
fragmentView.addView(gridLayout);

当我使用API14级中的GridLayout类时,这可以很好地工作,但是当我使用支持库(v7-r9)中的GridLayout时,我得到:

代码语言:javascript
复制
08-10 15:54:52.209: ERROR/AndroidRuntime(14687): FATAL EXCEPTION: main
    java.lang.NoClassDefFoundError: android.support.v7.gridlayout.R$dimen
    at android.support.v7.widget.GridLayout.<init>(GridLayout.java:255)
    at android.support.v7.widget.GridLayout.<init>(GridLayout.java:274)
    at android.support.v7.widget.GridLayout.<init>(GridLayout.java:282)
    at net.link.redbutton.fragment.PromotionLayoutFragment.showPromotions(PromotionLayoutFragment.java:168)
    at net.link.redbutton.fragment.PromotionLayoutFragment.onImageResult(PromotionLayoutFragment.java:222)
    at net.link.redbutton.fragment.SchedulerResponseFragment$1.onReceiveResult(SchedulerResponseFragment.java:37)
    at android.os.ResultReceiver$MyRunnable.run(ResultReceiver.java:43)
    at android.os.Handler.handleCallback(Handler.java:605)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4441)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    at dalvik.system.NativeStart.main(Native Method)
EN

回答 1

Stack Overflow用户

发布于 2012-08-13 17:34:53

事实证明,您需要将GridLayout支持库包含为一个安卓库项目(apklib),而不是jar。我使用的是maven Android SDK deployer,但目前有一个关于这方面的issue开放。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11905345

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档