自定义PupopWindow(带动画效果)
来源:互联网 发布:打赏危害网络直播 编辑:程序博客网 时间:2024/06/09 17:34
二话不说直接上代码
只用到了三个地方,MainActivity 和 MainActivity的布局 ,填充pupopwindow 的布局
MainActivity 代码
public class MainActivity extends AppCompatActivity implements View.OnClickListener { private RelativeLayout rl; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); rl = (RelativeLayout) findViewById(R.id.rl); } @Override public void onClick(View view) { switch (view.getId()) { case R.id.tv: ShowPopWindowShareToOther(); break; } } ImageView point_out_cha; CheckBox user_protocol_cb; TextView point_out_share_to_others; PopupWindow share_to_others_tips_pop;//分享提醒 private void ShowPopWindowShareToOther() { if (share_to_others_tips_pop == null) { View view = LayoutInflater.from(this).inflate(R.layout.layout_share_to_others, null); point_out_cha = (ImageView) view.findViewById(R.id.point_out_cha);//叉 user_protocol_cb = (CheckBox) view.findViewById(R.id.user_protocol_cb);//不再提示的选择框 point_out_share_to_others = (TextView) view.findViewById(R.id.point_out_share_to_others);//去分享 // 创建一个PopuWidow对象 share_to_others_tips_pop = new PopupWindow(view, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, true); } // 使其聚集 ,要想监听菜单里控件的事件就必须要调用此方法 share_to_others_tips_pop.setFocusable(true); // 设置允许在外点击消失 share_to_others_tips_pop.setOutsideTouchable(false); // 设置背景,这个是为了点击“返回Back”也能使其消失,并且并不会影响你的背景 share_to_others_tips_pop.setBackgroundDrawable(new BitmapDrawable()); //软键盘不会挡着popupwindow share_to_others_tips_pop.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
//设置pop的动画share_to_others_tips_pop.setAnimationStyle(R.style.showPopAnimation);// showPopAnimation在styles里//设置菜单显示的位置 share_to_others_tips_pop.showAtLocation(rl, Gravity.BOTTOM, 0, 0); point_out_share_to_others.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(MainActivity.this, "点击了去分享", Toast.LENGTH_SHORT).show(); //前往去分享 share_to_others_tips_pop.dismiss(); } }); point_out_cha.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { share_to_others_tips_pop.dismiss(); } }); }}
MainActivity的布局
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/rl" tools:context="com.example.popupwindow.MainActivity"> <TextView android:id="@+id/tv" android:onClick="onClick" android:textSize="20sp" android:padding="10dp" android:gravity="center_horizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="按钮"/></RelativeLayout>
最后一个就是填充PupopWindow的布局
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <RelativeLayout android:id="@+id/rl_point_out" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#3000" android:onClick="onClick"> <LinearLayout android:background="#3000" android:layout_width="268dp" android:layout_height="wrap_content" android:layout_centerInParent="true" android:orientation="vertical"> <RelativeLayout android:layout_width="match_parent" android:layout_height="150dp"> <ImageView android:id="@+id/point_out_cha" android:layout_width="36dp" android:layout_height="40dp" android:layout_alignParentRight="true" android:layout_marginRight="12dp" android:src="@mipmap/ic_launcher" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:paddingLeft="10dp" android:paddingRight="10dp" android:text="您需要将这条圈动态分享到:微信、QQ才能领取该红包,请知晓!" android:textSize="16sp" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_marginBottom="5dp" android:layout_marginLeft="10dp" android:layout_marginTop="10dp" android:gravity="center_vertical" android:orientation="horizontal"> <CheckBox android:id="@+id/user_protocol_cb" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="onClick" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="6dp" android:text="不再提醒" android:textSize="12sp" /> </LinearLayout> </RelativeLayout> <View android:layout_width="match_parent" android:layout_height="1dp" /> <LinearLayout android:layout_width="match_parent" android:layout_height="44dp" android:layout_alignParentBottom="true" android:orientation="horizontal"> <TextView android:id="@+id/point_out_share_to_others" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:gravity="center" android:text="去分享" android:textSize="16sp" /> </LinearLayout> </LinearLayout> </RelativeLayout></LinearLayout>styles 的代码:<style name="showPopAnimation" parent="android:Animation"> <!--name为调用这个style动画的名字,自己设置的--> <item name="android:windowEnterAnimation">@anim/slide_in_bottom</item><!--- 进入动画--> <item name="android:windowExitAnimation">@anim/slide_out_bottom</item><!-- 退出动画--></style>slide_in_bottom.xml:<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"> <translate android:interpolator="@android:anim/decelerate_interpolator" android:duration="500" android:fromXDelta="0%" android:toXDelta="0%" android:fromYDelta="100%" android:toYDelta="0%"/></set>slide_out_bottom.xml:<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"> <translate android:interpolator="@android:anim/decelerate_interpolator" android:duration="500" android:fromXDelta="0%" android:toXDelta="0%" android:fromYDelta="0%" android:toYDelta="100%"/></set>
阅读全文
0 0
- 自定义PupopWindow(带动画效果)
- Android_自定义底部动画弹出pupopwindow
- Android自定义环状进度条(带加载动画效果)
- 在Silverlight自定义验证效果(带动画)
- 自定义带动画效果的ProgressBar
- 自定义带动画效果的圆形ProgressBar
- swift3自定义UIBotton(带动画效果)
- pupopWindow。。。。
- 在Fragment中使用自定义的PopupWindow(带动画效果)
- 【Android进阶】自定义带动画切换效果的ViewPager
- Android 自定义带动画效果的开关按钮
- Android实现带动画效果的自定义View
- 自定义带删除按钮的 Edittext 并伴随动画效果
- Android 自定义带动画效果的开关按钮
- Android自定义动画之翻书效果带背影
- 按钮带动画效果(1)
- 按钮带动画效果(2)
- 相机手动对焦(带动画效果)
- JAVA内存泄露原因详细解释
- java的final关键字
- JAXB理解和应用实例
- 深度神经网络中梯度消失的原因及解决
- 高可用架构经验
- 自定义PupopWindow(带动画效果)
- redis 和phpredis安装
- Tensorflow深度学习之五:激活函数
- 输入挂与手动加栈
- JAVA必背面试题和项目面试通关要点
- Feel Good
- 设置程序默认以管理员身份打开(vs2010)
- Codeforces 734A
- React Native 启动白屏->引导页面->登录页面 例子