java - 为 Eclipse 设置 Android 支持包 v7 - GridLayout

标签 java android eclipse android-layout

我整个晚上都在尝试这个,但没有成功,所以我将从头开始列出我的确切步骤。

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

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


要设置支持包,我的步骤如下:

  • 右击我刚刚创建的项目,选择-新建- 安卓项目
  • 将其命名为 GridLayout 并选择从现有源中创建项目 并浏览至:

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).

那时我在我的项目中创建了一个名为“libs”的文件夹。

然后我将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)

我错过了/不应该做哪些事情?

最佳答案

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

  1. 将 GridLayout 项目设置为库项目。可以在 android 开发者网站 here 找到设置示例
  2. 像往常一样设置您的 ma​​in 项目,引用上面链接中描述的库项目。
  3. 将库添加到您的主项目。我用的是最新的android-support-v13.jar android-support-v7-gridlayout.jar . 注意: 我在 ma​​in 项目中使用了 v7 支持库,而不是库项目。事实上,现在检查一下 - 在库项目中我不引用 v7 支持。
  4. 在布局文件中使用完整的包名:<android.support.v7.widget.GridLayout />而不是 <GridLayout />
  5. 使用自定义命名空间,例如:xmlns:grid="http://schemas.android.com/apk/res-auto"在您的布局文件中使用标签中库项目中定义的自定义属性,例如 grid:columnCount

希望这会有所帮助。我目前正在尝试,甚至不确定这是我需要的东西:)

关于java - 为 Eclipse 设置 Android 支持包 v7 - GridLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10133078/

相关文章:

java - 如何在没有 Maven 的情况下将 GWT 和 Material Design Library 结合起来?

c# - 需要有关二进制 plist 的帮助

android - SQLCipher Loadlibs 和数据库密码更改

windows - 按下 R.Alt+键时如何防止激活 Ctrl+Alt+键绑定(bind)?

自定义安装处理程序的 Eclipse p2 替代方案

java - Android 应用程序无法在设备上启动

java - 由 : There is no result type defined for type 'chain' mapped with name 'success' 引起

java - 在运行时动态创建表和 Java 类

android - 我们是否有任何用于Android的开源库来创建pdf查看器应用程序?

android - 如何通过 adb 卸载 android 系统应用程序的更新?