美文网首页
fragment使用replace点击重叠问题

fragment使用replace点击重叠问题

作者: sun_goden | 来源:发表于2016-09-16 17:07 被阅读0次

    当主界面使用fragment的replace改变界面,列如fragmentA跳转到fragmentB,fragmentA中有listview的点击效果,它可以点击进入有内容的fragmentC,从fragmentA中跳转到fragmentB中,当在fragmentB中点击空白的的界面时,会点击到上一层的listview,所以会重新创建FragmentA,这就是fragment的点击穿透。
    一天的搜索尝试,在fragmenA和fragmentB中的根布局添加android:background=”@android:color/background_light

    这样fragment页面就不会重叠出现,但是他的点击事件还是有bug
    在尝试给每一个fragment中重写View.OnTouchListener的OnTouch方法,将返回值设置为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);
    }
    

    相关文章

      网友评论

          本文标题:fragment使用replace点击重叠问题

          本文链接:https://www.haomeiwen.com/subject/ayriettx.html