Grid Layout & API Level

2019-07-23 14:11发布

问题:

I want to use Grid Layout, but get the following error:

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

Is this because my API level is 9?

Does Grid Layout REALLY need API level 14? (I use Version: 8.0.1.v201012062107-82219)

  • If yes, what should I do? Please explain this step by step.
  • If no, so what's the reason? I'm doing exactly the same as the example!

回答1:

Here are the steps i spent to solve my problem:

To use GridLayout, i figured out many things should be upgraded.

  1. i had "jdk 7" installed on my system, so didn't need to upgrade it.
  2. i downloaded "installer_r20-windows.exe" and ran it.
  3. i downloaded "platforms" which contains "android-14", and copied it into android-sdk folder. (mine is: C:\ Android\android-sdk)
  4. i downloaded "system images" which contains "armeabi-v7a", and copied it into my sdk folder.
  5. i downloaded "platform-tools_r13-windows" and copied it into SDK folder.
  6. Then i found out also my eclipse is old, thus downloaded it's latest version, "eclipse 4.2_juno" (27 june 2012)
  7. i downloaded "Eclipse-plugins-ADT-20.0.zip". Then into eclipse: Help > Install New Software > Add > Archive > Eclipse-plugins-ADT-20.0.zip. Then select "Developer Tools" > click next > accept > click finish > restart eclipse.
  8. Again in eclipse: Window> Preferences > Android > SDK Location: path where my android-sdk folder exists.(e.g. mine is "C:\Android\android-sdk") > Apply > select "Android 4.0" > click OK.
  9. Then i created new AVD, from: eclipse > Window > AVD Manager > New..
  10. Finally, into sdk folder i created a new folder named "extras", into it another new folder named "android", into it another new folder named "support".
  11. Then i extracted content of "support_r09.zip" (which have downloaded it).

Now everything is ok..

Thanks to everybody helped me in this post (viperbone, Doomsknight, Matthieu, MemLeak,Jeroen).



回答2:

GridLayout needs API 14

You can create a Layout for the other android versions -> Adapt layout to Android platform or API level



回答3:

Yes, the GridLayout is only available if you run it on devices with API Level 14 or higher.

Not sure what that version 8.0.1.... is ? Definitely not the Android version.

If you plan to run your application on anything earlier than Ice Cream Sandwich I am afraid you have to use something else than that Layout. TableLayout maybe ? Or check this question

MORE (from comments):

Either you are ok with your app to run only on ICS or above (so somebody with a phone with Gingerbread will not be able to run it for example).

If yes, then:

  • Download the latest Android SDK
  • Set targetSDKversion="14" in your manifest

And this error should go away.

If no, then you CANNOT use GridLayout. You have a few options to replace it:

  • Download the library from : https://github.com/dlew/android-gridlayout and use that
  • Use some other layout (like TableLayout or LinearLayouts)


回答4:

In your manifest use:

<uses-sdk minSdkVersion="14" />

However, this will mean that any device running an Android API below 14 will not be able to use your app