Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
607 views
in Technique[技术] by (71.8m points)

grid layout - android.support.v7.widget.GridLayout cannot get it to work

I have an android project which utilizes GridLayout in most of its menus and screens. The problem however is that GridLayout is supported from API 14 and onwards.

Since I want to make the application available to older version of android as well, I tried to use Android's own Support Library GridLayout which adds support up to API 7. This was exactly what I was looking for, however I cannot for the life of me get it to work. I have tried all of these explanations and ideas:

  1. Android's official instructions
  2. Solution 1
  3. Solution 2
  4. Solution 3
  5. Solution 4
  6. Solution 5

and more...

No matter what I do, how I do it or what IDE I use (whether Eclipse ADT or Android Studio), it always gives me an error in the Layout XML along the lines of:

The following classes could be instantiated:  - android.support.v7.widget.GridLayout

With either one of these exceptions showing in the error log:

1. android.content.res.Resources$NotFoundException: Could not resolve value 0x7F080000
2. java.lang.classnotfoundexception: android.support.v7.gridlayout.R$dimen

Edit: For reference this is what I'm using to create the support gridlayout (taken directly from the android sample programs):

<android.support.v7.widget.GridLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/blue"
    android:padding="10dip"
    app:columnCount="4"
    >
    <TextView
        android:text="@string/string_test"
    />
    <EditText
        app:layout_gravity="fill_horizontal"
        app:layout_column="0"
        app:layout_columnSpan="4"
    />
    <Button
        android:text="@string/button_test"
        app:layout_column="2"
    />
</android.support.v7.widget.GridLayout>

What could I possibly be doing wrong that none of the above solutions work? Is there something I'm missing, maybe there's a problem with my original code?

Any help is appreciated

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try using Gradle, and in your build.gradle file add the following section at the end:

dependencies {
  implementation 'com.android.support:gridlayout-v7:28.0.0'
  implementation 'com.android.support:appcompat-v7:28.0.0'
}

Then execute assembleDebug gradle task.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...