2012-04-12 76 views
34

我一直在尝试这一整个晚上都无济于事,所以我要从头开始列出我的确切步骤。为eclipse设置Android支持包v7 - GridLayout

  • 我已经安装了通过SDK管理器支持包。
  • 我创建了一个新的android项目,我称之为“testinggridlayout”。
  • 构建目标我选择的是Android 2.1 API 7
  • 列表项

这将是我的项目,我希望能够创建一个网格 布局。


要建立支持包这些是我的步骤:

  • 右键单击我刚刚创建的项目,并选择 - 新 - 的Android项目
  • 将它命名为网格布局,并选择从现有的源 创建项目,请浏览:

android-sdks\extras\android\support\v7\gridlayout

  • 右键单击我的testinggridlayout项目,然后单击属性:
  • 下Java构建路径 - 选择项目选项卡,然后添加。
  • 选择我的项目“GridLayout”,然后单击确定,然后确定。

此时

如果我进入的main.xml布局手动插入此代码:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" > 

<GridLayout 
    android:background="#FFFFFF" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:columnCount="8" 
    android:rowCount="5" > 

</GridLayout> 

</LinearLayout> 

我得到的错误:

The following classes could not be found: - GridLayout (fix build path, edit XML).

如果我改变

<GridLayout> & </GridLayout>

<android.support.v7.widget.GridLayout> & </android.support.v7.widget.Gridlayout>

我收到了同样的错误:

The following classes could not be found: - android.support.v7.widget.GridLayout (fix build path, edit XML).

在这一点上我创造了我的项目被称为“库”的文件夹。

然后,我将GridLayout项目中的libs下的android-support-v7-GridLayout.jar文件复制到此文件夹中。

我在“testinggridlayout”的“libs”文件夹中右键单击了该文件,并选择了“添加到构建路径”。然后

我的错误更改为:

The following classes could not be instantiated: - android.support.v7.widget.GridLayout (open class, show error log)

哪个位(S)我已经错过了/不应该做?

回答

15

我使用intellij的想法,所以它不完全是你的情况,但也许它会有帮助。我努力设置这一整天,然后突然工作。我将描述我的设置,以便您可以进行比较:

  1. 将GridLayout项目设置为库项目。设置示例可在Android开发人员网站找到here
  2. 设置您的主要项目照常,请参考上面链接中所述的库项目。
  3. 将库添加到您的主项目中。我用最新的android-support-v13.jarandroid-support-v7-gridlayout.jar注意:我在主要项目中使用了v7支持库,而不是库项目。事实上,现在检查它 - 在库项目我不参考 v7的支持。
  4. 使用在布局文件完整的包名称:中<android.support.v7.widget.GridLayout />代替<GridLayout />
  5. 使用自定义空间,像这样:xmlns:grid="http://schemas.android.com/apk/res-auto"在使用中你的标签库项目的自定义特性的布局文件,如grid:columnCount

希望这有助于。我目前正在尝试它,甚至不知道它是我需要的东西:)

+1

对我来说,日食要求安装支持包,但还是没”不承认它。对我来说,只是使用Android.support.v7.widget.GidLayout修复它。谢谢! – Niels 2012-11-03 23:24:45

4

support-v7-gridlayout.jar修订版7有一些问题。 现在它已更新到修订版8,see compatibility-library只是更新它,它的工作。 不要忘记更改所有库和依赖关系的支持包,否则会出现不匹配错误。

10

如果有人有同样的问题,这里是为我工作的解决方案:

导入项目进入你需要将其添加为使用Android的标签,而不是Java构建路径

项目依赖一个工作区后 - >属性 - >安卓 - >库 - > [添加...]

我也打勾是库。

1

除了上面我列出的建议必须做一件事之前,我可以在Eclipse中预览网格布局:

  1. 右键单击该项目的Android支持-V7-网格布局。
  2. 前往属性> Java构建路径>库
  3. 将libs/android-support-v7-gridlayout.jar添加到库中。
  4. 转到“订单和导出”并检查在上一步中添加的罐子。

希望它有帮助!

2

编辑您的项目(和库项目的太).classpath文件是这样的:

<?xml version="1.0" encoding="UTF-8"?> 
<classpath> 
    <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> 
    <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/> 
    <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> 
    <classpathentry kind="src" path="src"/> 
    <classpathentry kind="src" path="gen"/> 
    <classpathentry kind="output" path="bin/classes"/> 
</classpath> 
+0

将主要项目和android-support-v7-gridlayout项目中的exported =“true”属性添加到com.android.ide.eclipse.adt.ANDROID_FRAMEWORK classpathentry中,然后重新启动Eclipse为我工作。 – 2013-10-31 17:33:44

5

复制Android的支持-V7-gridlayout.jar从文件夹Android_SDK_folder \演员\机器人\ SUPPORT \ v7 \ gridlayout \ libs。然后,将其粘贴到您的项目MyAndroidProject \ libs文件夹中。

+1

这还不够,你只是在复制文件 – sports 2014-08-08 17:05:29

0

为了7V样品(/演员/安卓/支持/样本/ Support7Demos /)工作,做到以下几点:

  1. 导入所有从这里的项目/演员/安卓/支持/ V7
  2. 创建/库目录Support7Demos项目
  3. 把所有* .jar文件在这些项目的/ libs目录,并把它们添加到Support7Demos /库