效果图
步骤:
1.布局中添加分享按钮
2.画出分享页面
3.设置分享页面animator进出动画,并在style.xml中配置
4.MainActivity中添加方法
*画出布局
主页面: <Button android:id="@+id/share" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="分享" android:onClick="share"/> 分享页面: <TextView android:id="@+id/textview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="share" android:textSize="30sp" />
*设置动画效果
//in.xml <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration = "1000" android:fromYDelta="100%" android:toYDelta="0"></translate> </set> //out.xml <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration = "1000" android:fromYDelta="0" android:toYDelta="100%"></translate> </set> //styles.xml <style name="my_popupWindow_style"> <item name="android:windowEnterAnimation">@animator/in</item> <item name="android:windowExitAnimation">@animator/out</item> </style>
*MainActivity添加方法
public void share(View view) {
View shareView = LayoutInflater.from(this).inflate(R.layout.popupwindow_share, null);
PopupWindow popupWindow = new PopupWindow(shareView, LinearLayout.LayoutParams.MATCH_PARENT,200);
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.setAnimationStyle(R.style.my_popupWindow_style);
popupWindow.showAtLocation(view, Gravity.BOTTOM,0,0);
}