2017-09-27 69 views
0

我嘗試把一個imageview的頂部顯示一個標誌,但是當我運行應用程序,我有這樣的錯誤:android.view.InflateException時使用的ImageView

android.view.InflateException: Binary XML file line #13: Error inflating class android.widget.ImageView

,如果我刪除的ImageView代碼運行沒有問題

我怎麼可以在這裏解決,這是activity_main.xml中

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:background="#2e3138" 

    tools:context="dattasolutions.cloud.dattasolutionscloud.MainActivity" 
    android:orientation="vertical" 
    > 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="60dp" 
     android:src="@drawable/logo" 
     android:id="@+id/imageView" 
     /> 

    <TextView 

     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:textSize="17sp" 
     android:id="@+id/tvHeading" 
     android:text="Presiona el icono para subir archivos al servidor" 
     android:textColor="#fff" 
     android:textStyle="bold" 
     android:layout_marginTop="64dp" /> 
    <ImageView 
     android:id="@+id/ivAttachment" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:src="@drawable/attach_icon" 
     android:layout_centerVertical="true" 
     android:layout_centerHorizontal="true" 
     android:layout_x="145dp" 
     android:layout_y="171dp" /> 

    <TextView 
     android:id="@+id/tv_file_name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textColor="#fff" 
     android:layout_marginTop="10dp" 
     android:gravity="center" 
     android:layout_below="@+id/ivAttachment" 
     android:layout_centerHorizontal="true"/> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/b_upload" 
     android:text="Upload" 
     android:textStyle="bold" 
     android:textSize="20sp" 
     android:layout_alignParentBottom="true" 
     android:gravity="center" 
     android:textColor="#fff" 
     android:background="#039be5"/> 



</RelativeLayout> 

enter image description here

+0

你的圖像是一個矢量圖標或PNG? –

+0

再往下看logcat。你應該看到另一個指向真正問題的錯誤。如果你不明白髮生了什麼,請在這裏發佈錯誤。 – Cheticamp

+0

png圖片及其唯一的400kb – jtaco263

回答

2

嘗試替換。 android:src="@drawable/logo"

With。
app:srcCompat="@drawable/logo"
請參閱reason

如果它仍然不起作用,然後檢查圖像的大小。有時候這不是真正的膨脹問題,而是更深層的問題,即導致通貨膨脹例外的記憶問題。使用最小尺寸的圖片。 希望它有幫助。

+0

app:srcCompat =「@ drawable/logo」會導致錯誤,但android:srcCompat =「@ drawable/logo」不會顯示圖像 – jtaco263

+0

嘗試使用不同的圖像進行測試更小的尺寸。 – Journey

+0

圖像大小接近400kb – jtaco263

0

可能是問題出在你的名爲「標誌」圖像嘗試一些其他的圖像,並檢查它是否是圖像格式或大小等等。這樣的問題,你會很容易來了解問題以及在未來中應該使用什麼類型的圖像。祝你好運!

相關問題