1、要使用渐变效果首先需要给布局文件的跟节点添加一个id
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rl_root"
android:layout_width="match_parent"
android:layout_height="match_parent">
2、在代码onCreate方法中 设置渐变属性
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 创建一个从0.1到完全显示的渐变
AlphaAnimation animation = new AlphaAnimation(0.1f,1f);
//渐变显示执行过程两秒钟
animation.setDuration(2000);
//获取布局跟节点
RelativeLayout rlRoot = (RelativeLayout) findViewById(R.id.rl_root);
//开启渐变效果
rlRoot.startAnimation(animation);
}