gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 18:56:45 25 4
gpt4 key购买 nike

在 android 中,是否可以完全以编程方式从支持库创建 GridLayout(即不编写相应的 xml)?

我在 fragment (称为 PromotionLayoutFragment)中创建我的 GridLayout,如下所示:

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)

最佳答案

事实证明,您需要将 GridLayout 支持库包含为 Android 库项目 (apklib),而不是 jar。我正在使用 Maven Android SDK deployer , 但目前有一个 issue对此持开放态度。

关于android - 从支持库以编程方式创建 GridLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11905345/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com