16

我有一個Android項目,它在大部分菜單和屏幕中都使用GridLayout。然而問題是GridLayout是從API 14開始支持的。android.support.v7.widget.GridLayout無法啓動它

因爲我想讓應用程序可以使用老版本的android,所以我嘗試使用Android自己的支持庫GridLayout,它增加了對API 7的支持。 這正是我所期待的,但是我不能爲了我的生活得到它的工作。我已經嘗試了所有這些解釋和想法:

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

和MOR è...

不管我做什麼,我該怎麼辦呢還是我用的IDE(Eclipse中是否ADT或Android工作室),它總是給我沿着線的佈局XML錯誤:

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 

編輯:供參考,這是我用來創建支持網格佈局(直接從Android示例程序採取)什麼:

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

我該怎麼辦可能是做錯了,沒有任何上述解決方案工作?有什麼我錯過了,也許有我的原始代碼有問題?

任何幫助表示讚賞

+0

把你的xml代碼 – nsvir

+0

@nsvir - 添加我的XML代碼,雖然沒有什麼特別的,但我使用了Android – user475680

回答

4

藉助Android工作室:

  • 圍棋中的build.gradle並添加:

    compile 'com.android.support:appcompat-v7:18.0.+' 
    

    在您的依賴。

  • 通過單擊AVD管理器左側的圖標來同步您的項目。它將實現庫

  • ,然後再試一次

使用Eclipse試試這個:Gridview v7 support for older api android.support.v7.widget.Gridlayout failed to instaniate

+0

給出的示例代碼我使用的代碼運行時沒有gradle(當試圖通過Eclipse創建一個代碼時顯示錯誤,並沒有做任何事情),我看到這個解決方案,但因爲我不使用gradle它不可行 – user475680

+0

嘗試我的編輯爲Eclipse – nsvir

+0

已經嘗試過它...不適合我 – user475680

38

嘗試使用搖籃,並在你的build.gradle文件的末尾添加以下部分:

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

然後執行assembleDebug gradle任務。

+1

這應該是被接受的答案。 在ADT(Eclipse)中導入v24 appcompat和更高版本將不起作用。構建工具不再存儲兼容ADT的庫,從.aar中提取過多的工作 - 考慮轉移到Android Studio和基於Gradle的構建系統。 – milosmns

1

在我來說,我固定它設置:

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="18" /> 
在gridlayout_v7項目清單文件

相關問題