2017-10-09 998 views

回答

0

我認爲最好的方法是使用所有你的意見(有可能用的FrameLayout),這裏是你的XML後面的ImageView的: (你可以使用不同的scaleType)

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

      <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:scaleType="centerInside" 
      android:src="@mipmap/background"/> 

      <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 



      <!-- put your views here --> 




      </RelativeLayout> 


</FrameLayout> 
0

以編程方式,你可以這樣做。 在不同的活動中,您可以使用相同的佈局文件。 爲您的佈局命名: - myLayout 爲佈局定義一個變量。 受保護的視圖myLayoutView; 閱讀佈局作爲視圖 myLayoutView =(查看)findViewById(R.id.myLayout); 然後設置背景如下: myLayoutView.setBackground((Drawable)myBackground);

以上所有內容都是在您的活動的onCreate方法中編寫的。您可以隨時更改背景。

佈局中可能有其他幾個視圖可能會在屏幕上顯示其內容,也可能存在動畫,但背景仍保持靜態。