我整个晚上都在尝试这个,但没有成功,所以我将从头开始列出我的确切步骤。
- 我已经通过 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,所以这不完全是您的情况,但也许会有所帮助。我整天都在努力设置它,然后它突然起作用了。我将描述我的设置,以便您进行比较:
- 将 GridLayout 项目设置为库项目。可以在 android 开发者网站 here 找到设置示例
- 像往常一样设置您的 main 项目,引用上面链接中描述的库项目。
- 将库添加到您的主项目。我用的是最新的
android-support-v13.jar
和android-support-v7-gridlayout.jar
. 注意: 我在 main 项目中使用了 v7 支持库,而不是库项目。事实上,现在检查一下 - 在库项目中我不引用 v7 支持。 - 在布局文件中使用完整的包名:
<android.support.v7.widget.GridLayout />
而不是<GridLayout />
- 使用自定义命名空间,例如:
xmlns:grid="http://schemas.android.com/apk/res-auto"
在您的布局文件中使用标签中库项目中定义的自定义属性,例如grid:columnCount
希望这会有所帮助。我目前正在尝试,甚至不确定这是我需要的东西:)
关于java - 为 Eclipse 设置 Android 支持包 v7 - GridLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10133078/