2016-05-26 41 views
-2

我試圖通過XML圖像添加背景片段:如何添加圖像(jpg)背景片段

<FrameLayout 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:background="@drawable/background" 
tools:context="com.example.ronen.sunplantnew.Fragments.Loading"></FrameLayout> 

但它好好嘗試的工作,還當我試圖將其添加到活動(相對layour - 片段containee)
我也試過:

<FrameLayout 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" 
tools:context="com.example.ronen.sunplantnew.Fragments.Loading"> 

<ImageView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/background" 
    android:src="@drawable/background" 
    android:scaleType="centerCrop" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentEnd="true" /></FrameLayout> 

但它也doen't工作 所以我怎樣才能添加背景片段?

+0

你的第一個代碼適用於我。 –

+0

使用'android:background =「@ drawable/ic_launcher」'而不是'android:background =「@ drawable/background」'來檢查代碼的有效性! –

+0

它適用於android:background =「@ drawable/ic_launcher」 –

回答

1

Android不支持GIF。使用jpg圖片,或者使用AnimationDrawable作爲this answer優惠。

在使用JPG圖像的情況下,確保有一個background.jpg文件中的RES /繪製文件夾中。

+0

我做了一個錯誤,這是一個JPG圖像 –