2016-07-27 144 views
0

我正在製作一個咖啡訂購應用程序,其中我想將背景圖像完全覆蓋整個屏幕(注意:圖像存在於我放置在Google的可繪製文件夾中)。背景圖片在Android Studio中無法使用。 (嘗試所有以前的解決方案在StackOverflow上給出)

我試圖用佈局android:background="@drawable/cof"放置背景圖片,但它不工作。它顯示這個錯誤:

enter image description here

我甚至試圖把不同的圖像,但它不能正常工作,並顯示以下錯誤。

佈局:

<LinearLayout 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:orientation="vertical" 
    android:layout_margin="16dp" 
    android:background="@drawable/cof" 

    > 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="20sp" 
     android:text="QUANTITY" 
     android:layout_marginBottom="16dp" 
     /> 
    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     > 
     <Button 
      android:layout_width="48dp" 
      android:layout_height="48dp" 
      android:text="-" 
      android:onClick="decrement"/> 
     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="18sp" 
      android:layout_marginLeft="8dp" 
      android:layout_marginRight="8dp" 
      android:text="2" 
      /> 
     <Button 
      android:layout_width="48dp" 
      android:layout_height="48dp" 
      android:text="+" 
      android:onClick="increment" 
      /> 

    </LinearLayout> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="25sp" 
     android:layout_marginTop="16dp" 
     android:text="Price" 
     android:layout_marginBottom="16dp"/> 
    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="20sp" 
     android:text="Rs 10"/> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="16dp" 
     android:textSize="28sp" 
     android:text="ORDER" 
     android:onClick="submitOrder"/> 
</LinearLayout> 
+0

什麼截圖? – Shaishav

+0

請提供錯誤文本和文件「cof」。 –

+0

對不起忘了附加scrrenshot.ok沒問題我會給你錯誤,它出現在'預覽屏幕':渲染問題 - 無法解決資源「@ drawable/cof」.Failed to convert @ drawable/cof into a可以顯示「 - 這是在預覽屏幕上顯示的信息,什麼是錯誤,讓我知道我能做些什麼來完成我的工作 – Ayush

回答

0

繪製對象不能爲HTML文件。

請參考可繪製documentation

如果你想放置一個圖像只接受.png,.jpg或.gif!

如果你想顯示一個HTML頁面,那麼你必須使用WebView

+0

@Ayush它有用嗎? – LaurentY

0

請檢查名爲「cof」的文件是可繪製資源。它應該是.png文件,或者它應該是.xml文件。如果它是一個PNG文件,嘗試使用MS繪圖或Photoshop再次將其保存爲png圖像,有時在Android Studio中重命名或更改圖像擴展的原因問題時。

0

如果您想要顯示html文件,您不能將.htm或.html文件設置爲背景,您必須使用WebView並通過在WebView上重疊其他視圖來將其視爲背景。

0

/drawable文件夾只能有以下類型resoruces中的一種:

"Bitmap files (.png, .9.png, .jpg, .gif) or XML files that are compiled into the following drawable resource subtypes: : Bitmap files - Nine-Patches (re-sizable bitmaps) - State lists - Shapes - Animation drawables - Other drawables - "

0

我也是個初學者到Android,但我認爲這主要是發生在你沒有使用圖片與正確的格式。你應該使用.png格式。在我看來,加載背景圖片的代碼是正確的。

相關問題