PopupWindowFragment :使用Fragment來管理和生成PopupWindow,并且提供更好的定制化接口,比DialogFragment更加強(qiáng)大實(shí)用###
GitHub 地址:<a >PopupWindowFragment</a>
Bug反饋地址: dingwei.chen1988@gmail.com
<strong>簡介:</strong>
- <p>PopupWindowFragment是為了在Fragment模型中更好,更方便的使用PopupWindow而存在的通用組件。跟DialogFragment類似,也是將一個(gè)新的Window對(duì)象納入Fragment的狀態(tài)管理僵娃。但是由于DialogFragment的功能及接口的局限性,已經(jīng)很難滿足更加復(fù)雜的界面要求莱坎。因此,使用接口更加豐富的PopupWindow代替Dialog的方式應(yīng)運(yùn)而生矫渔。</p>
- 在PopupWindowFragment中,你除了可以輕松的指定Window切換時(shí)候的過場動(dòng)畫,還可以動(dòng)態(tài)指定背景及布局外,在屏幕翻轉(zhuǎn)的時(shí)候,PopupWindowFragment一樣會(huì)記錄翻轉(zhuǎn)前的狀態(tài)摇幻。
1.使用方法:
/**生成一個(gè)PopupWindowFragment
* @code david.demos.popupwindow.DemoPopupWindowFragment
*/
public class DemoPopupWindowFragment extends PopupWindowFragment {
@Override
protected View onCreateView(LayoutInflater inflater, Bundle savedInstanceState) {
return inflater.inflate(R.layout.demo_pop_window,null);
}
}
/**Activity中調(diào)用
* @code david.demos.popupwindow.Demos_PopupWindowFragment
*/
private PopupWindowFragment mPopupWindowFragment = new DemoPopupWindowFragment();
...
mPopupWindowFragment.show(getFragmentManager(),mPopTag);
調(diào)用PopupWindowFragment的方法就是如此簡單岭皂。當(dāng)然,這部分剪口很大一部分參考了DialogFragment的接口設(shè)計(jì)存捺。調(diào)用上述方法后可以實(shí)現(xiàn)效果:
2.過場動(dòng)畫:
當(dāng)然PopupWindowFragment可以做的事情遠(yuǎn)不止此,PopupWindowFragment可以通過簡單的request方法來定制你的過場動(dòng)畫:
/**Activity中調(diào)用
* @code david.demos.popupwindow.Demos_PopupWindowFragment
*/
private int[] mWindowAnims = {
PopupWindowFragment.ANIM_ACTIVITY,
PopupWindowFragment.ANIM_TOAST,
PopupWindowFragment.ANIM_DIALOG,
PopupWindowFragment.ANIM_INPUTMETHOD
};
...
mPopupWindowFragment.requestPopupAnimationStyle(mWindowAnims[index]);
...
PopupWindowFragment將默認(rèn)提供4個(gè)過場動(dòng)畫,分別是Activity動(dòng)畫,Toast動(dòng)畫,Dialog彈出動(dòng)畫,還有輸入法動(dòng)畫,效果如下:
3.狀態(tài)保存:
PopupWindowFragment擁有Fragment的保存特質(zhì),可以在Activity切換的時(shí)候依舊保持自己的狀態(tài):
4.定制Gravity:
//demo/Demos_PopupWindowFragment.java
private int[] mGravitys = {Gravity.BOTTOM,Gravity.CENTER,Gravity.TOP};
...
mPopupWindowFragment.requestGravity(mGravitys[i]);
....
效果:
PopupWindowFragment提供了豐富的API和接口供各位開發(fā)者使用,如果疑問和Bug,請(qǐng)發(fā)送到作者郵箱贼邓。thx