當(dāng)主界面使用fragment的replace改變界面,列如fragmentA跳轉(zhuǎn)到fragmentB,fragmentA中有l(wèi)istview的點擊效果,它可以點擊進(jìn)入有內(nèi)容的fragmentC,從fragmentA中跳轉(zhuǎn)到fragmentB中,當(dāng)在fragmentB中點擊空白的的界面時,會點擊到上一層的listview,所以會重新創(chuàng)建FragmentA,這就是fragment的點擊穿透。
一天的搜索嘗試,在fragmenA和fragmentB中的根布局添加android:background=”@android:color/background_light
”
這樣fragment頁面就不會重疊出現(xiàn),但是他的點擊事件還是有bug
在嘗試給每一個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);
}