1.ViewPager里面Fragment滑动卡顿
问题:如果Fragment添加背景图的时候,滑动ViewPager会很卡。
如果把背景图去掉,滑动又变得流畅。
百度后发现:
引用背景图时,图片要放在mipmap包中
将图片从drawable中转移到mipmap后,滑动ViewPager就正常了
2. Fragment加载的布局页面里的控件无法使用onClick属性
会报以下错误:
java.lang.IllegalStateException: Could not find method onLogout(View) in a parent or ancestor Context for android:onClick attribute defined on view class android.widget.TextView with id 'id_logout'
原因:Fragment不是布局器,不具备渲染视图的能力,虽然可以管理布局器,但它管理的布局器最终要加载到一个ViewGroup对象内,由ViewGroup对象来渲染,而ViewGroup并不知道每一个子控件来源于哪里。
解决方法:可以在Fragment的onCreatedView 方法中使用匿名内部类实现setOnClickListener()方法