以编程方式从支持库创build一个GridLayout

android中,是否有可能从支持库完全编程创build一个GridLayout(即没有写入相应的XML)?

我创build我的GridLayout在一个片段(称为PromotionLayoutFragment),像这样:

ViewGroup fragmentView = (ViewGroup)getView(); GridLayout gridLayout = new GridLayout(fragmentView.getContext()); gridLayout.setColumnCount(2); gridLayout.setRowCount(15); // add views to grid ... fragmentView.addView(gridLayout); 

当我使用API​​级别14中的GridLayout类时,这工作正常,但是当我从支持库(v7-r9)使用GridLayout时,我得到:

 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) 

Related of "以编程方式从支持库创build一个GridLayout"

事实certificate,您需要将GridLayout支持库包含为Android库项目(apklib),而不是jar。 我正在使用Maven的Android SDK部署 ,但目前有一个问题打开这一点。