我有一个Android项目,它在大多数菜单和屏幕中使用GridLayout.然而问题是从API 14及以后版本支持GridLayout.
由于我想让应用程序也可用于旧版本的android,我尝试使用Android自己的支持库GridLayout,它增加了对API 7的支持.这正是我所寻找的,但是我不能为我的生活让它工作.我尝试了所有这些解释和想法:
和更多...
无论我做什么,我是怎么做的,或者我使用的是什么IDE(无论是Eclipse ADT还是Android Studio),它总是在布局XML中给出一个错误:
The following classes could be instantiated: - android.support.v7.widget.GridLayout
With either one of these exceptions showing in the error log:
1. android.content.res.Resources$NotFoundException: Could not resolve value 0x7F080000
2. java.lang.classnotfoundexception: android.support.v7.gridlayout.R$dimen
Run Code Online (Sandbox Code Playgroud)
编辑:作为参考,这是我用来创建支持gridlayout(直接从android示例程序):
<android.support.v7.widget.GridLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/blue"
android:padding="10dip"
app:columnCount="4"
>
<TextView
android:text="@string/string_test"
/>
<EditText
app:layout_gravity="fill_horizontal"
app:layout_column="0"
app:layout_columnSpan="4"
/>
<Button
android:text="@string/button_test"
app:layout_column="2"
/>
</android.support.v7.widget.GridLayout>
Run Code Online (Sandbox Code Playgroud)
如果上述解决方案都不起作用,我可能做错了什么?有什么我想念的,也许我的原始代码有问题吗?
任何帮助表示赞赏
android grid-layout android-gridlayout android-support-library
我试图从支持库中加入GridLayout,但它无法正常工作.我的目标版本是API版本10.我使用的XML代码如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<android.support.v7.widget.GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:grid="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android.support.v7.widget.columnCount="6" >
<Button
android:id="@+id/button1"
android.support.v7.widget.layout_column="1"
android.support.v7.widget.layout_columnSpan="2"
android.support.v7.widget.layout_gravity="left"
android.support.v7.widget.layout_row="1"
android:text="Button" />
</android.support.v7.widget.GridLayout>
Run Code Online (Sandbox Code Playgroud)
当Eclipse尝试编译它时,给出的错误是:android.support.v7.widget.GridLayout无法实例化.堆栈跟踪是:
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 sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:402)
at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:166)
at com.android.layoutlib.bridge.android.BridgeInflater.loadCustomView(BridgeInflater.java:205)
at com.android.layoutlib.bridge.android.BridgeInflater.createViewFromTag(BridgeInflater.java:133)
at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
at android.view.LayoutInflater.inflate(LayoutInflater.java:296)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:279)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:318)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:325)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderService.createRenderSession(RenderService.java:372)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(GraphicalEditorPart.java:1361)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout(GraphicalEditorPart.java:1115)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.activated(GraphicalEditorPart.java:941)
at com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate.delegatePageChange(LayoutEditorDelegate.java:585)
at com.android.ide.eclipse.adt.internal.editors.common.CommonXmlEditor.pageChange(CommonXmlEditor.java:360)
at org.eclipse.ui.part.MultiPageEditorPart$2.widgetSelected(MultiPageEditorPart.java:290)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:240)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
at …Run Code Online (Sandbox Code Playgroud) 我在IntelliJ项目中设置支持v7 GridLayout库或在我的代码中正确引用它时遇到了麻烦.
我目前在我的项目中使用ActionBarSherlock和Facebook库,并以相同的方式设置了支持GridLayout库(在src文件夹中没有源代码,我告诉IntelliJ使用项目目录作为jar文件夹).一切看起来很好,构建和部署到我的测试设备,但当我试图给布局充气时,我的应用程序崩溃了.
09-17 17:07:43.916: ERROR/AndroidRuntime(4143): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example/com.example.MainHostActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class android.support.v7.widget.GridLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2753)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2769)
at android.app.ActivityThread.access$2500(ActivityThread.java:129)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2117)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4717)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class android.support.v7.widget.GridLayout
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.decoderhq.indieshuffle.PlayerFragment.onCreateView(PlayerFragment.java:63)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:846)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1061)
at …Run Code Online (Sandbox Code Playgroud) android intellij-idea grid-layout classnotfoundexception android-support-library
我正在尝试使用columnCount属性,android.support.v7.widget.GridLayout但出现错误
错误:(2)在包中找不到属性“useDefaultMargins”的资源标识符
我用过了 xmlns:app="http://schemas.android.com/apk/res-auto
android widget grid-layout android-library android-support-library