弹窗动画PopupWindow
生活随笔
收集整理的這篇文章主要介紹了
弹窗动画PopupWindow
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
//設置PopupWindow
public void showPopupWindow(View view){ //準備彈窗所需要的視圖對象View v = LayoutInflater.from(this).inflate(R.layout.popup_layout,null);//1.實例化對象//參數1:用在彈窗中的View//參數2,3:彈窗的寬高//參數4(focusable):能否獲取焦點PopupWindow window = new PopupWindow(v,500,100,true);//2.設置(背景,動畫)//背景window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));//能響應外部的點擊事件window.setOutsideTouchable(true);//設置彈窗能響應點擊事件window.setTouchable(true);//①創建動畫資源,②創建一個style應用動畫資源,③對當前彈窗的動畫風格設置為第二部的資源索引window.setAnimationStyle(R.style.translate_anim);//3.顯示//參數1(anchor):錨//參數2,3:相對于錨在x,y方向上的偏移量window.showAsDropDown(view,-500,0);//為彈窗中的文本添加事件//這里所需要的id不能直接找到,要用視圖v調用v.findViewByIdv.findViewById(R.id.choose).setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {Toast.makeText(MainActivity3.this, "您點擊了選擇", Toast.LENGTH_SHORT).show();window.dismiss();//控制彈窗消失}});v.findViewById(R.id.choose_all).setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {Toast.makeText(MainActivity3.this, "您點擊了全選", Toast.LENGTH_SHORT).show();window.dismiss();}});v.findViewById(R.id.copy).setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View view) {Toast.makeText(MainActivity3.this, "您點擊了復制", Toast.LENGTH_SHORT).show();window.dismiss();}});
}
?-------------------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"><translateandroid:fromXDelta="0"android:toXDelta="0"android:fromYDelta="800"android:toYDelta="0"android:duration="2000"> <!--duration:設置移動時間(毫秒)--></translate> </set>在theme里添加動畫類型
?基礎設置
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="horizontal"android:layout_width="match_parent"android:layout_height="match_parent"android:background="#ffffff"android:padding="2dp"><TextViewandroid:id="@+id/choose"android:layout_width="60dp"android:layout_height="30dp"android:text="選擇"android:textColor="#ffffff"android:gravity="center"android:background="#000000"/><Viewandroid:layout_width="2dp"android:layout_height="30dp"android:background="#00ffff"/><TextViewandroid:id="@+id/choose_all"android:layout_width="60dp"android:layout_height="30dp"android:text="全選"android:textColor="#ffffff"android:gravity="center"android:background="#000000"/><Viewandroid:layout_width="2dp"android:layout_height="30dp"android:background="#00ffff"/><TextViewandroid:id="@+id/copy"android:layout_width="60dp"android:layout_height="30dp"android:text="復制"android:textColor="#ffffff"android:gravity="center"android:background="#000000"/><Viewandroid:layout_width="2dp"android:layout_height="30dp"android:background="#00ffff"/></LinearLayout>總結
以上是生活随笔為你收集整理的弹窗动画PopupWindow的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Win10系统无法安装geforce g
- 下一篇: 127Echarts - 关系图(Gra