美文网首页
Android PopupWindow在某个控件正下方显示,附带

Android PopupWindow在某个控件正下方显示,附带

作者: _祥_1990 | 来源:发表于2017-05-20 22:43 被阅读0次

刚开始做的使用用的translate动画,弄出来的效果很突兀,后来改用scale,达到leader的要求,给需要同样效果的你。效果图:


a.gif

代码:

Java部分


<pre>
PopupWindow pop;
private void showPop(){
if(pop==null){
pop=new PopupWindow(this);
pop.setWidth(tvPopupWindowAnimation.getWidth());
pop.setHeight(280);
pop.setAnimationStyle(R.style.PopupWindowAnimStyle);
pop.setFocusable(true);
pop.setTouchable(true);
pop.setBackgroundDrawable(
new ColorDrawable(ContextCompat.getColor(getApplicationContext(),R.color.colorPrimary)));
View v=new View(this);
v.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
     ViewGroup.LayoutParams.MATCH_PARENT));
pop.setContentView(v);
}
if(!pop.isShowing()){
int[] position=new int[2];
tvPopupWindowAnimation.getLocationOnScreen(position);
pop.showAtLocation(tvPopupWindowAnimation, Gravity.NO_GRAVITY,position[0],
position[1]+ tvPopupWindowAnimation.getHeight());
}
}
</pre>

style部分

<pre>

<style name="PopupWindowAnimStyle">
    <item name="android:windowEnterAnimation">@anim/in_like_drop_down</item>
    <item name="android:windowExitAnimation">@anim/out_like_shrink_on</item>
</style>

</pre>

anim部分

in_like_drop_down

<pre>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200">
<scale
android:fromXScale="1.0"
android:fromYScale="0.0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toXScale="1.0"
android:toYScale="1.0" />
</set>
</pre>

out_like_shrink_on

<pre>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200">
<scale
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:toXScale="1.0"
android:toYScale="0.0"/>
</set>
</pre>

相关文章

网友评论

      本文标题:Android PopupWindow在某个控件正下方显示,附带

      本文链接:https://www.haomeiwen.com/subject/fzzpxxtx.html