PopupWindow

  • 自定义PopupWindow

有一个黑色的背景,是从下往上平移出来的

代码部分:
dialog_sell_product_layout:

<?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="#C8000000"
    android:gravity="center"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:background="@drawable/bg_white"
        android:gravity="center_horizontal"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="25dp"
            android:text="修改库存与价格"
            android:textColor="#1a1a1a"
            android:textSize="18sp" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="50dp"
                android:layout_marginTop="20dp"
                android:orientation="horizontal" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="价格:"
                    android:textColor="#333333"
                    android:textSize="14sp" />

                <EditText
                    android:id="@+id/ed_waybill_number"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="@null"
                    android:hint="请输入商品价格"
                    android:inputType="numberDecimal"
                    android:paddingLeft="6dp"
                    android:singleLine="true"
                    android:textColor="@color/colorText"
                    android:textColorHint="@color/colorHintText"
                    android:textSize="14sp" />
            </LinearLayout>
            <View
                android:layout_marginTop="10dp"
                android:layout_marginLeft="50dp"
                android:layout_marginRight="50dp"
                style="@style/horizontal_line"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="50dp"
                android:layout_marginTop="20dp"
                android:orientation="horizontal" >

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="库存:"
                    android:textColor="#333333"
                    android:textSize="14sp" />

                <EditText
                    android:id="@+id/ed_logistics_company"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:background="@null"
                    android:hint="请输入库存数量"
                    android:inputType="numberDecimal"
                    android:paddingLeft="6dp"
                    android:singleLine="true"
                    android:textColor="@color/colorText"
                    android:textColorHint="@color/colorHintText"
                    android:textSize="14sp" />
            </LinearLayout>
            <View
                android:layout_marginTop="10dp"
                android:layout_marginLeft="50dp"
                android:layout_marginRight="50dp"
                style="@style/horizontal_line"/>
        </LinearLayout>
        <LinearLayout 
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_marginTop="20dp"
            android:layout_marginBottom="25dp"
            android:gravity="center_horizontal"
            android:orientation="horizontal"
            >

            <TextView 
                android:id="@+id/tv_storage_confirm"
                android:layout_width="70dp"
                android:layout_height="match_parent"
                android:background="@drawable/bg_login_selector"
                android:textColor="@color/white"
                android:gravity="center"
                android:textSize="14sp"
                android:text="确定"/>
            <TextView 
                android:layout_marginLeft="10dp"
                android:id="@+id/tv_storage_cancle"
                android:layout_width="70dp"
                android:layout_height="match_parent"
                android:background="@drawable/bg_login_selector"
                android:textColor="@color/white"
                android:gravity="center"
                android:textSize="14sp"
                android:text="取消"/>
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

pay_tip_anim:

<style name="pay_tip_anim">
        <item name="android:windowEnterAnimation">@anim/pay_tip_in</item>
        <item name="android:windowExitAnimation">@anim/pay_tip_out</item>
    </style>

pay_tip_in, pay_tip_out

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate android:fromYDelta="100%p" android:toYDelta="0" android:duration="500"/>
</set>

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">   
   <translate android:fromYDelta="0" android:toYDelta="100%p" android:duration="500"/>
</set>

真正的运用:

        View view = inflater.inflate(R.layout.dialog_sell_product_layout, null);
        PopupWindow popupWindow = new PopupWindow(view, w, h);
        //点击外面的时候 消失
        popupWindow.setOutsideTouchable(true);
        //使其聚焦
        popupWindow.setFocusable(true);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        popupWindow.setAnimationStyle(R.style.pay_tip_anim);
        //第一个参数:父布局 第二个参数:相对于父布局的位置的下方  第三个参数 :无偏移
        popupWindow.showAtLocation(activity.findViewById(R.id.sell_product), Gravity.BOTTOM, 0, 0);
        popupWindow.update();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值