android:toYDelta=“100%p” />
然后在代码中布置好动画:
Intent intent = new Intent(BeforeActivity.this, AfterActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.bottom_in,R.anim.bottom_silent);
第二步:写activity的manifest配置:
//我们要将其设置为可以透明显示的
<activity
android:name=“.XXXActivity”
android:theme=“@style/XXXTheme”>
<meta-data
android:name=“android.max_aspect”
android:value=“ratio_float” />
第三步,在Activity的代码中设置状态栏透明:
//XXXActivity
@Override
protected void onCreateView(Bundle savedInstanceState) {
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_song_detail);
getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
第四步:设置Activity的布局XML文件:
<?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”
xmlns:tools=“http://schemas.android.com/tools”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
tools:context=“.song.mvp.view.SongDetailActivity”>
//View用来铺整个View,因为我们的RelativeLayout会用到background,这样的话如果有圆角,会出现很僵硬的白色
//我们也是根据这个view来做透明
<View
android:id=“@+id/view”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:background=“#636363”/>
<RelativeLayout
android:layout_width=“match_parent”
android:layout_height=“match_parent”>
<View
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:layout_above=“@+id/rl_bottom” />
<RelativeLayout
android:id=“@+id/rl_bottom”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:background=“#ffffff”
android:layout_alignParentBottom=“true”>
…
其实到这里已经差不多,但是Activity的出现会带一块黑黑的屏(就是我们透明view)进来,效果不太好
所以我们要让一开始这个view是透明的,在动画完成后该view变成半透明的
通过写alpha动画:
//view的透明变半透明
动画
//view_to_translate
<alpha
android:duration=“200”
android:fromAlpha=“0”
android:toAlpha=“0.7”/>
然后在Activity onStart的时候执行这个动画:
//设置延迟开始的时间还蛮关键的,能决定动画是否平滑
@Override
protected void onStart() {
super.onStart();
if (toTranslateIn == null) {
toTranslateIn = AnimationUtils.loadAnimation(this, R.anim.view_to_translate_in);
toTranslateIn.setFillAfter(true);
toTranslateIn.setStartOffset(200);
}
findViewById(R.id.vi
资料获取→专栏
ew).startAnimation(toTranslateIn);
nUtils.loadAnimation(this, R.anim.view_to_translate_in);
toTranslateIn.setFillAfter(true);
toTranslateIn.setStartOffset(200);
}
findViewById(R.id.vi[外链图片转存中…(img-U1bN3jsS-1718728855985)]
资料获取→专栏
ew).startAnimation(toTranslateIn);