2012-04-12 77 views
34

我一直在嘗試這一整個晚上都無濟於事,所以我要從頭開始列出我的確切步驟。爲eclipse設置Android支持包v7 - GridLayout

  • 我已經安裝了通過SDK管理器支持包。
  • 我創建了一個新的android項目,我稱之爲「testinggridlayout」。
  • 構建目標我選擇的是Android 2.1 API 7
  • 列表項

這將是我的項目,我希望能夠創建一個網格 佈局。


要建立支持包這些是我的步驟:

  • 右鍵單擊我剛剛創建的項目,並選擇 - 新 - 的Android項目
  • 將它命名爲網格佈局,並選擇從現有的源 創建項目,請瀏覽:

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

在這一點上我創造了我的項目被稱爲「庫」的文件夾。

然後,我將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)

哪個位(S)我已經錯過了/不應該做?

回答

15

我使用intellij的想法,所以它不完全是你的情況,但也許它會有幫助。我努力設置這一整天,然後突然工作。我將描述我的設置,以便您可以進行比較:

  1. 將GridLayout項目設置爲庫項目。設置示例可在Android開發人員網站找到here
  2. 設置您的主要項目照常,請參考上面鏈接中所述的庫項目。
  3. 將庫添加到您的主項目中。我用最新的android-support-v13.jarandroid-support-v7-gridlayout.jar注意:我在主要項目中使用了v7支持庫,而不是庫項目。事實上,現在檢查它 - 在庫項目我不參考 v7的支持。
  4. 使用在佈局文件完整的包名稱:中<android.support.v7.widget.GridLayout />代替<GridLayout />
  5. 使用自定義空間,像這樣:xmlns:grid="http://schemas.android.com/apk/res-auto"在使用中你的標籤庫項目的自定義特性的佈局文件,如grid:columnCount

希望這有助於。我目前正在嘗試它,甚至不知道它是我需要的東西:)

+1

對我來說,日食要求安裝支持包,但還是沒」不承認它。對我來說,只是使用Android.support.v7.widget.GidLayout修復它。謝謝! – Niels 2012-11-03 23:24:45

4

support-v7-gridlayout.jar修訂版7有一些問題。 現在它已更新到修訂版8,see compatibility-library只是更新它,它的工作。 不要忘記更改所有庫和依賴關係的支持包,否則會出現不匹配錯誤。

10

如果有人有同樣的問題,這裏是爲我工作的解決方案:

導入項目進入你需要將其添加爲使用Android的標籤,而不是Java構建路徑

項目依賴一個工作區後 - >屬性 - >安卓 - >庫 - > [添加...]

我也打勾是庫。

1

除了上面我列出的建議必須做一件事之前,我可以在Eclipse中預覽網格佈局:

  1. 右鍵單擊該項目的Android支持-V7-網格佈局。
  2. 前往屬性> Java構建路徑>庫
  3. 將libs/android-support-v7-gridlayout.jar添加到庫中。
  4. 轉到「訂單和導出」並檢查在上一步中添加的罐子。

希望它有幫助!

2

編輯您的項目(和庫項目的太).classpath文件是這樣的:

<?xml version="1.0" encoding="UTF-8"?> 
<classpath> 
    <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/> 
    <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/> 
    <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/> 
    <classpathentry kind="src" path="src"/> 
    <classpathentry kind="src" path="gen"/> 
    <classpathentry kind="output" path="bin/classes"/> 
</classpath> 
+0

將主要項目和android-support-v7-gridlayout項目中的exported =「true」屬性添加到com.android.ide.eclipse.adt.ANDROID_FRAMEWORK classpathentry中,然後重新啓動Eclipse爲我工作。 – 2013-10-31 17:33:44

5

複製Android的支持-V7-gridlayout.jar從文件夾Android_SDK_folder \演員\機器人\ SUPPORT \ v7 \ gridlayout \ libs。然後,將其粘貼到您的項目MyAndroidProject \ libs文件夾中。

+1

這還不夠,你只是在複製文件 – sports 2014-08-08 17:05:29

0

爲了7V樣品(/演員/安卓/支持/樣本/ Support7Demos /)工作,做到以下幾點:

  1. 導入所有從這裏的項目/演員/安卓/支持/ V7
  2. 創建/庫目錄Support7Demos項目
  3. 把所有* .jar文件在這些項目的/ libs目錄,並把它們添加到Support7Demos /庫