【问题标题】:IntelliJ: Getting GridLayout workIntelliJ:让 GridLayout 工作
【发布时间】:2016-03-07 19:18:40
【问题描述】:

我尝试在我的应用程序中使用 GridLayout,但它不起作用。 我使用了这个教程:IntelliJ and android.support.v7.widget.GridLayout

但还是不行。

我收到以下错误:

error: No resource identifier found for attribute 'columnCount' in package 'android'
error: No resource identifier found for attribute 'rowCount' in package 'android'

还有什么建议吗?

编辑: 使用我的实际 XML:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:grid="http://schemas.android.com/apk/res-auto"
              android:layout_width="350dp"
              android:layout_height="fill_parent"
              android:orientation="vertical">

    <EditText android:layout_height="wrap_content"
              android:layout_width="fill_parent"
              android:cursorVisible="false"
              android:id="@+id/txtName"/>


    <android.support.v7.widget.GridLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            grid:columnCount="3"
            grid:rowCount="2">

        <TextView   
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="1,1" />
     
    </android.support.v7.widget.GridLayout>

</LinearLayout>

【问题讨论】:

  • 发布您的完整布局——您是否定义了 android 命名空间?另外,您的 API 目标是什么?
  • 我编辑了我的 xml。我使用 Google 2.2 API
  • 尝试将属性命名空间改回android。
  • 您是如何将 v7 兼容库添加到您的项目中的?你是粘贴 jar 还是使用 Gradle?

标签: android grid-layout


【解决方案1】:

今天我为此苦苦挣扎,在android dev site 我找到了更简单的解决方案以及为什么它们会出现问题。 v7 库中的 GridLayout 未与 v7 appcompat 库连接,因此您必须手动添加 v7 gridlayout 库依赖项。

如果你使用 gradle,那么在 build.gradle 中添加

dependencies {
    ...
    compile 'com.android.support:gridlayout-v7:23.2.0'
}

一切都应该正常:)

【讨论】:

  • 有人能解释一下为什么你需要com.android.support:appcompat-v7:18.+ 和这个gridlayout-line 吗?您需要单独包含哪些其他视图?
  • @Nilzor :我发现 appcompat 和 gridlayout 是两个独立的库。因此,它们应该在 build.gradle 中单独提及。您可以在此处查看更多详细信息:developer.android.com/tools/support-library/features.html
【解决方案2】:

您需要使用完整的包和类名:

<android.support.v7.widget.GridLayout>

并添加命名空间,以便其他控件使用默认包:

xmlns:grid="http://schemas.android.com/apk/res-auto"

【讨论】:

  • +1,很好,我不知道网格命名空间。我还没用过GridLayout。
  • 还是不行。 :(我编辑了我的第一篇文章。谢谢你的帮助!:)
  • 你编辑了什么?你是说你使用了完整的包名并添加了 res-auto 命名空间,你得到了同样的错误?
  • 是的。我在第一篇文章中编辑了 xml。我用命名空间和完整的包名做对了吗?
  • this is not working - 这告诉我我需要知道的一切!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-02
  • 2018-01-11
  • 1970-01-01
  • 2014-10-02
相关资源
最近更新 更多