PopupWindow的使用


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>


可以使用了。哈哈哈哈哈我们每一天都要进步哟

                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值