您的位置:首页 > 其它

安卓-bug记录

2016-08-18 11:36 337 查看

1.假如listview的item中有Button,ImageButton,CheckBox等会强制获取焦点的view此时,listview的item无法获取焦点,从而无法被点击

      解决方法:给item的根布局增加以下属性    android:descendantFocusability="blocksDescendants"     设置之后,Button获取焦点,item中其他控件也可以获取焦点

2.首页轮播图的小圆点第一次安装软件滚动,以后启动不滚动

Bug原因:

联网请求后缓存了json数据,第二次登录的时候先读取了缓存,小圆点的集合在addHeadPoints()方法里添加了数据,联网成功后小圆点的集合在addHeadPoints()方法里又添加了一次,产生冲突,

解决办法:

在addHeadPoints()方法里给小圆点的集合添加数据之前先滞空;

3.


原因:

tv_home_car_num.setText(result.getData().getCart_num()); 这句给tv_home_car_num赋值

其中result.getData().getCart_num()是int值

解决:

把result.getData().getCart_num()改为String值


4.ListView 添加头、尾 时异常

①出现重复:

出现原因:

没有控制头或者尾只添加一次。

private boolean
isAdd =
false;
if
(!isAdd) {
    View header = initHeadView();
    View foot = initFootView();
    cartList.addHeaderView(header);
    cartList.addFooterView(foot);
    cartList.setAdapter(adapter);
    isAdd
= true;
}
 

② 头为ViewPager时,不显示。

解决:在ViewPager的布局外面套一个线性布局

③ GridView 不显示:GridView父布局加背景 如:

 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:background="#ffffff"

    android:orientation="vertical">

 

<GridView

    android:id="@+id/gv_fg_foot"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:numColumns="4"/>

</LinearLayout>

④ java.lang.IllegalStateException: Cannot add header view to list -- setAdapter has already been called.

 

原因:必须在setAdapter之前执行addHeaderView方法,否则会出现以下异常

cartList.addHeaderView(header);
cartList.addFooterView(foot);
cartList.setAdapter(adapter);
 

5.ListView嵌套在ViewPager中,切换ViewPager后再切换到ListView页面时,需要把适配器置空,并重新设置适配器

6.java.lang.IllegalStateException:The specified child already has a parent. You must call removeView() on the child's parent first.

for (View view : viewList) {

            ViewGroup p = (ViewGroup) view.getParent();

            if (p != null) {

                p.removeAllViewsInLayout();

            }

        }

 

7.popupwindow相关

if(popupWindow == null) {

            popupWindow = new PopupWindow(contentView, ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT);

        }

        popupWindow.setBackgroundDrawable(new BitmapDrawable());//设置背景

        popupWindow.setFocusable(true);//点击外部时获得焦点

        popupWindow.setOutsideTouchable(true);//外部可点击

        popupWindow.setTouchable(true);//popupwindow可点击

 

@Override

    public boolean onTouchEvent(MotionEvent event) {//外部触发触摸事件时popupwindow消失

        popDismiss();

        return super.onTouchEvent(event);

    }

 8. DrawerLayout相关:

  点击DrawerLayout的头部布局默认会触发被其遮盖的下层界面的视图的点击事件。因此,需要重写其onTouchEvent()方法,返回值为true。


9.头像裁剪时,拍照产生的大图片无法加载进自定义加载框

解决:先进行边缘解析(设置inJustDecodeBounds属性),获取图片宽高,再采取合适的采样率算法,将图片压缩,进而解决问题。

10.ListView或者GridView里, 每个item的CheckBox, 尤其是全局还有多个全选按钮时, 会因为checkbox的状态改变监听而互相干扰

可以通过使用ImageView代替checkBox, 并给图片的背景加上selected选择器, 最后使用图片的点击监听来改变选择状态来解决问题

11.Gson数据类型错误, 导致解析错误

gsonFormat自动解析数据时,尤其是json数组时, 会根据第0个item的数据来生生成实体类, 这时候, 例如价格要使用浮点类型, 但是因为第一个item的价格是整数, gsonformat很有可能会直接将其声明为整数类型, 这样装载数据时就会出现问题,有的gson即使出现问题也不会报错, 只会崩溃(原因有可能是因为异常日志被管理工具拦截, 没有打印到控制台), 因此这个问题要在gsonformat生成实体时仔细检查数据类型是否正确, 否则后期排查会非常困难

12.RecyclerView cannot notify while compling or scrolling

原因有可能是产生了死循环, RecyclerView内部大量使用了handler, 因此这种情况一方面要解决死循环问题, 另一方面可以通过Handler发送post任务, 将notify语句作为任务发送出去, 以此来避免冲突

13.EventBus重复发送同一条广播

首先,EventBus使用时接收端需要注册, 不用时接收端需要解注册, Eventbus后台会使用集合来管理注册过的tag, 即使该tag曾被我们释放并重新创建, 但只要释放时没有解注册, 就会导致重复注册, 每一次释放创建都会导致EventBus管理的集合中多出一份该类的tag, 最终引起消息的重复发送, 这种问题在单层的activity中容易解决, 只要在生命周期的最后阶段解注册就行, 重点强调嵌套层数比较多, 关联度较高的页面, 退出时解注册一定要解注册
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: