简述
本文仅供参考,主要用于进出场动画讲解,如有不足之处,希望大家理解
Layout-->xml
//设置布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="123"
android:id="@+id/ll"
/>
</LinearLayout>
anim-->xml
// 进场
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="2000">
<alpha android:fromAlpha="1" android:toAlpha="0"/>
<translate android:fromXDelta="100%p"
android:fromYDelta="100%p"
android:toXDelta="0"
android:toYDelta="0"
/>
</set>
//离场
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="2000">
<alpha android:fromAlpha="0" android:toAlpha="1"/>
<translate android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="100%p"
android:toYDelta="100%p"
/>
</set>
values-->styes
<style name="Popupwindow" parent="android:style/Animation">
<item name="android:windowEnterAnimation">@anim/set_enter</item>
<item name="android:windowExitAnimation">@anim/set_exit</item>
</style>
Activity中
//创建PopupWindow
View view = LayoutInflater.from(PagerThreeActivity.this).inflate(R.layout.popu, null);
final PopupWindow popupWindow = new PopupWindow(view,
GridView.MarginLayoutParams.MATCH_PARENT, GridView.MarginLayoutParams.MATCH_PARENT);
popupWindow.setAnimationStyle(R.style.Popupwindow);
popupWindow.showAsDropDown(view, 0, 0);
popupWindow.setClippingEnabled(true);
Myy(0.5f);
//设置监听
//点击button 离场
view.findViewById(R.id.ll).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popupWindow.dismiss();
Myy(1);
}
});
//点击阴影离场
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popupWindow.dismiss();
Myy(1);
}
});
//阴影
public void Myy(float b) {
WindowManager.LayoutParams attributes = getWindow().getAttributes();
attributes.alpha = b;
getWindow().setAttributes(attributes);
}