PopupWindow的使用

来源:互联网 发布:js get url parameter 编辑:程序博客网 时间:2024/06/10 01:45
1.把需要的布局加载到popupwindow
2.设置popupwindow的大小
3.设置显示的位置
public class CustomPopupWindow extends PopupWindow{    public CustomPopupWindow(View view, int style) {        // 设置SelectPicPopupWindow的View        this.setContentView(view);        // 设置SelectPicPopupWindow弹出窗体的宽        this.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);        // 设置SelectPicPopupWindow弹出窗体的高        this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);        //加入动画        this.setAnimationStyle(style);        this.setFocusable(true);        this.setOutsideTouchable(true);        // 刷新状态        this.update();        ColorDrawable dw = new ColorDrawable(0000000000);        this.setBackgroundDrawable(dw);    }}
XML动画文件
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" >    <!-- 定义从透明到可见 -->    <alpha android:fromAlpha="1.0"        android:toAlpha="0.0"        android:duration="5000"        /><!--缩放-->    <scale        android:duration="5000"        android:fromXScale="1.0"        android:fromYScale="1.0"        android:pivotX="50%"        android:pivotY="50%"        android:toXScale="2.0"        android:toYScale="2.0"        />    <!--旋转-->    <rotate        android:duration="5000"        android:fromDegrees="360"        android:toDegrees="-360"        android:pivotX="50%"        android:pivotY="50%"        />    <!--移动-->    <translate        android:duration="5000"        android:fromXDelta="1080"        android:fromYDelta="1920"        android:toXDelta="0"        android:toYDelta="0"        /></set>
<?xml version="1.0" encoding="utf-8"?>  <set xmlns:android="http://schemas.android.com/apk/res/android" >    <!-- 定义从可见到透明 -->    <alpha android:fromAlpha="1.0"        android:toAlpha="0.0"        android:duration="300"        /></set>
<?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:background="#ffffff"    android:orientation="vertical">    <TextView        android:layout_width="match_parent"        android:layout_height="50dp"        android:background="#de2323"        android:gravity="center"        android:text="选择主题"        android:textColor="#ffffff" />  <!--  <GridView        android:id="@+id/gridview"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:numColumns="5"        android:scrollbars="none"></GridView>-->    <TextView        android:layout_width="100dp"        android:layout_height="50dp"        android:layout_gravity="center"        android:background="#de2323"        android:gravity="center"        android:text="取消"        android:textColor="#ffffff" /></LinearLayout>
<!-- PopupWindow动画的效果样式 --><style name="AnimationWindow">    <item name="android:windowEnterAnimation">@anim/pop_in</item>    <item name="android:windowExitAnimation">@anim/pop_out</item></style>


可以使用了。哈哈哈哈哈我们每一天都要进步哟
                                             
1 0
原创粉丝点击