PopupWindow分享页面

效果图

步骤:

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);
}
复制代码

 

posted @   嘉禾世兴  阅读(505)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示