2017-10-09 989 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方法中编写的。您可以随时更改背景。

布局中可能有其他几个视图可能会在屏幕上显示其内容,也可能存在动画,但背景仍保持静态。