簡體   English   中英

如何在ADT Project for Eclipse中導入庫

[英]How can I import a library in ADT Project for Eclipse

我試圖查找並導入Makeramen庫,因為我無法復制我的項目並收到以下錯誤:

錯誤信息:

Multiple annotations found at this line:
    - error: No resource identifier found for attribute 'border_color' in package 'myapp'
    - error: No resource identifier found for attribute 'mutate_background' in package 'myapp'
    - error: No resource identifier found for attribute 'border_width' in package 'myapp'
    - error: No resource identifier found for attribute 'oval' in package 'myapp'

我的xml:

 <com.makeramen.RoundedImageView xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/mapImage"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="@drawable/list_map_bar"
            android:padding="12dp"
            android:scaleType="fitCenter"
            android:src="@drawable/list_world"
            app:border_color="@color/xroads_grey"
            app:border_width="2dp"
            app:mutate_background="true"
            app:oval="true" />

我不知道如何解決此問題,並運行和復制android項目。 有人可以幫助我嗎?

非常感謝!


更新2

我收到了一個導入到ADT-Eclipse的Android項目。 缺少一些庫,請檢查下面的完整結構項目圖像:

Android項目(對不起,我可以上傳圖片,因為stackoverflow不允許我上傳任何圖片):

LoginActivity
    -Android 4.3
    -Referenced Libraries
        -rundedimageview-1.5.0-sources.jar
    -src
    -gen [Generated Java Files]
    -assets
    -bin
    -libs
    -res
    -AndroidManifest.xml
    -ic_launcher-we.png
    -lint.xml
    -project.properties

在/ res / layout文件夾下,我在本主題之前提到的文件上有一些錯誤消息,原因是缺少庫和依賴項。 因此,我將RoundedImageView JAR添加到了項目中,但是沒有任何變化。

有任何想法嗎? 讓我知道是否有人需要有關任何文件的更多信息或錯誤消息。 它缺少build.gradle文件,這是正常的還是我如何創建?

更新3:

我按照Nadeem Iqbal的建議更改了代碼,但錯誤仍然存​​在。 我可以在代碼中出現這些錯誤的情況下運行該應用。 請幫忙!

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res/io.cran.crossroads"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

  <FrameLayout
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:id="@+id/map"
        android:layout_alignBottom="@+id/avatar"
        android:layout_toRightOf="@id/imageBarLeft">

        <com.makeramen.RoundedImageView 
            android:id="@+id/mapImage"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="@drawable/list_map_bar"
            android:padding="12dp"
            android:scaleType="fitCenter"
            android:src="@drawable/list_world"
            app:border_color="@color/xroads_grey"
            app:border_width="2dp"
            app:mutate_background="true"
            app:oval="true" />
    </FrameLayout>

在您的最上層根視圖中添加此行

xmlns:app="http://schemas.android.com/apk/res/YOUR.PACKAGE.NAME"

像這樣:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res/YOUR.PACKAGE.NAME"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

        <com.makeramen.RoundedImageView
            android:id="@+id/mapImage"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:background="@drawable/list_map_bar"
            android:padding="12dp"
            android:scaleType="fitCenter"
            android:src="@drawable/list_world"
            app:border_color="@color/xroads_grey"
            app:border_width="2dp"
            app:mutate_background="true"
            app:oval="true" />

</RelativeLayout>

看來您可以在這里找到您的庫的源代碼: https : //github.com/vinc3m1/RoundedImageView

下載它,然后嘗試在Eclipse中導入roundedImageView文件夾。 將此項目設置為一個庫(項目>屬性> Android),然后轉到您自己的項目並添加該庫(項目>屬性> Android>添加)。

您缺少attrs值。 這些應該已經存在於圖書館項目中。 嘗試從頭開始重新導入庫。

 <?xml version="1.0" encoding="utf-8"?>
<resources>
  <declare-styleable name="RoundedImageView">
    <attr name="corner_radius" format="dimension" />
    <attr name="border_width" format="dimension" />
    <attr name="border_color" format="color" />
    <attr name="mutate_background" format="boolean" />
    <attr name="oval" format="boolean" />
    <attr name="android:scaleType" />
  </declare-styleable>
</resources>

以防萬一

由於XML名稱空間問題,您將收到這些錯誤。 在您的xml中,應將xmlns:app="http://schemas.android.com/apk/res-auto"更改為

xmlns:app="http://schemas.android.com/apk/lib/com.makeramen.roundedimageview"

注意-

/ res更改為/ lib

另外,將包名稱com.makeramen.RoundedImageView更改為

com.makeramen.roundedimageview.RoundedImageView

嘗試這個:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/lib/com.makeramen.roundedimageview"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >

<com.makeramen.roundedimageview.RoundedImageView
    android:id="@+id/avatar"
    android:layout_width="55dip"
    android:layout_height="55dp"
    android:layout_centerInParent="true"
    android:scaleType="centerCrop"
    android:src="@drawable/daimajia"
    app:border_color="#ffffff"
    app:border_width="1dp"
    app:corner_radius="10dip"
    app:mutate_background="true"
    app:oval="true" />

</RelativeLayout>

希望這能解決您的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM