當(dāng)主界面使用fragment的replace改變界面,列如fragmentA跳轉(zhuǎn)到fragmentB,fragmentA中有l(wèi)istview的點(diǎn)擊效果,它可以點(diǎn)擊進(jìn)入有內(nèi)容的fragmentC,從fragmentA中跳轉(zhuǎn)到fragmentB中,當(dāng)在fragmentB中點(diǎn)擊空白的的界面時(shí),會(huì)點(diǎn)擊到上一層的listview,所以會(huì)重新創(chuàng)建FragmentA,這就是fragment的點(diǎn)擊穿透。
一天的搜索嘗試,在fragmenA和fragmentB中的根布局添加android:background=”@android:color/background_light
”
這樣fragment頁面就不會(huì)重疊出現(xiàn),但是他的點(diǎn)擊事件還是有bug
在嘗試給每一個(gè)fragment中重寫View.OnTouchListener的OnTouch方法,將返回值設(shè)置為true
如:
public boolean onTouch(View v,MotionEvent event){
Return true;
}
Public View .onCreatView(LayoutInflater inflater ,ViewGroup container,Bundle savedInstanceStace){
View view=inflater.inflate(R.layout.fragment,null);
View .setonTouchListener(this);
}