bug集

(1)listview黑屏:

           <style name="AttentionListView" parent="@android:style/Widget.ListView">
        <item name="android:listSelector">@drawable/lmall_transparent</item>
        <item name="android:fadingEdge">none</item>
        <item name="android:cacheColorHint">#00000000</item>
        <item name="android:divider">@null</item>
        <item name="android:scrollbarThumbVertical">@drawable/lmall_base_list_scrollbar_handle</item>
        </style>

        listview 设置

      <com.wangzhi.mallLib.view.PullToRefreshListView
             android:id="@+id/lMListView1"
             style="@style/AttentionListView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#ffffff"
            android:divider="@null" >
     </com.wangzhi.mallLib.view.PullToRefreshListView>

       若是还是黑屏,则将item的父背景去掉应该就ok了

 

//listview 设置n个头部,就要size-n个头部,否则就会报错

listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {// 跳转至试用详情页
// 友盟数据埋点
AnalyticsEvent.applyListAnalyticsEvent(TryoutApplyListActivity.this, "2");
// 试用中心-首页点击按钮-埋点
TryoutTools.collectTryoutBtnStringData(TryoutApplyListActivity.this, PAGE_NAME, null,
"SYZXB_APPLYLIST_DETAIL_ONGOING");
 // 有两个头部
 final int index = position - 2;
 if (index >= 0 && index < applyDataList.size()) {
startApplyDetailActivity(TryoutApplyListActivity.this, applyDataList.get(position - 2));
}
}
});

  (2) 手机时间转换的时候,一定要写上时区,否则手机默认的时区可能不对,导致转换的时间就不对

(3)onActivityResult不被执行

          1、activity.startActivityForResult(intent, REQ_EDIT_REPORT_CODE);//REQ_EDIT_REPORT_CODE>0必须大于0

           2、intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//intent不能设置这个标志

          3、目标的启动模式launchMode:

                <1> 在standard、singleTop两个模式下,onActivityResult方法会在当前的Activity结束掉之后被调用

           <2>在singleTask、singleInstance两个模式下,onActivityResult方法会立即调用,等到再setResult的时候,就不再起作用了

      4、系统浏览器崩溃:提示android No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://b.mashort.cn/S.uRdF1sm=ca229a (has extras) }  

             原因是:dat的url有空格,需要用trim(),去掉空格就好

5、java 静态变量问题:

      

public static String NetAddr = "";//正式环境为"",alpha环境为"alpha.",beta环境为"beta."
public static  String mall_host = "http://xxx." + NetAddr + "xxx.com";

即使在代码中修改NetAddr的值为beta.(即NetAddr="beta.")但是mall_host的值依旧是"http://xxx.xxx.com"不会变为"http://xxx.beta.xxx.com"

 

原因是:当NetAddr的值重新赋值为beta.时"http://xxx.beta.xxx.com"这串字符串会重新分配一个静态区域空间,而mall_host的指向地址没改变还是指向原先的字符串"http://xxx.xxx.com"

若是要改变mall_host的值需要和NetAddr一样重新再代码在赋值一遍,改变mall_host的指向,即在代码中mall_host="http://mall." + NetAddr + "lmbang.com";

6 :layout_width和layout_height 这是针对父布局所在的宽高,如果没有父布局,则设置此宽高无效,还是按照wrapcontent,这就是为什么叫做layout_width不叫width的原因

如图:

 

这个xml设置linearLayout设置layout_width = 120dp layout_height=120dp,使用inflate加载,参数root = null

 

xml显示的布局效果: 

   

    

而 实际运行效果为:

解决办法: 在LinearLayout外面套一层viewGroup 如framelayout就可以解决:因为layout_width是相对父布局的布局

7、ScrollView(垂直滑动)HorizontalScrollView(水平滑动) :都只能放置一个子view,因为继承的是Framlayout;由于只重写scrollTo,所以要滚动到指定位置不要使用scrollBy,否则定位不准确;使用scrollTo定位是比较准确的

例子代码:将屏幕分成三份(至多只显示三个tab)选中的tab居中

 

<pre name="code" class="java">/**
	 * 
	 * @description 设置定位到指定的位置
	 * @author zhongwr
         *@params view 被选中的view
	 * @update 2015-11-30 下午3:53:31
	 */
	private void scrollToPosition(final View view) {
		scrollView.post(new Runnable() {

			@Override
			public void run() {// 被选中的tab居中
				int left = view.getLeft();
				left = left - screenWidthOneThird;
				scrollView.scrollTo(left, 0);
			}
		});
	}

	/** 屏幕的三分之一 */
	private int screenWidthOneThird = Tools.getScreenSize(mActivity).x / 3;

	/**
	 * 
	 * @description 添加tab栏
	 * @author zhongwr
	 * @update 2015年9月1日 下午5:24:44
	 */
	@SuppressLint("ResourceAsColor")
	private void addTabsAndFragments() {
		if (!Tools.isListEmpty(allBabyTabList)) {
			llTabContainer.setVisibility(View.VISIBLE);
			llTabContainer.removeAllViews();
			int size = allBabyTabList.size();
			LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(0,
					ViewGroup.LayoutParams.WRAP_CONTENT, 1.0f);
			layoutParams.leftMargin = 30;
			layoutParams.rightMargin = 30;
			layoutParams.gravity = Gravity.CENTER;
			layoutParams.width = screenWidthOneThird - 60;// 左右两边间距
			TextView tvTab = null;
			GestateBabyTabItem tabItem = null;
			for (int i = 0; i < size; i++) {
				tabItem = allBabyTabList.get(i);
				tvTab = createTabTextView(tabItem, layoutParams, i, size);
				tvTab.setOnClickListener(new MyOnClickListener(tabItem.tabIndex));
				tabTextViewList.add(tvTab);
				if (1 == tabItem.selected) {// 当前选中的
					currIndex = tabItem.tabIndex;
					tvCurrTab = tvTab;
					tvTab.setTextColor(getResources().getColor(R.color.red_1));
					fragmentList.add(GestateKnowledgeBabyTabFragment.newInstance(tabItem.id, babyDataItem));
				} else {
					fragmentList.add(GestateKnowledgeBabyTabFragment.newInstance(tabItem.id, null));
				}
				llTabContainer.addView(tvTab);
			}
		} else {
			llTabContainer.setVisibility(View.GONE);
			setReloadVisiable();
		}
	}

	/**
	 * 
	 * @description 宝宝月份:分类的tab的textview
	 * @author zhongwr
	 * @update 2015年9月1日 下午5:31:05
	 */
	private TextView createTabTextView(GestateBabyTabItem tabItem, LinearLayout.LayoutParams layoutParams,
			int position, int size) {
		TextView tvBabyTab = new TextView(this);
		tvBabyTab.setText(tabItem.value);
		tvBabyTab.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13);
		tvBabyTab.setPadding(0, 17, 0, 17);
		tvBabyTab.setTextColor(getResources().getColor(R.color.gray_7));
		tvBabyTab.setGravity(Gravity.CENTER);
		if (null != layoutParams) {
			tvBabyTab.setLayoutParams(layoutParams);
		}
		return tvBabyTab;
	}

 

 

 

 

7、Fragment在viewpager中,onHiddenChanged()方法是不会执行的,可以使用setUserVisibleHint方法,此方法必须使用getUserVisibleHint来获取当前fragment当前显示的布尔状态值(isVisibleToUser),否则不准确

8、调用浏览器的最佳方式

     

Intent intent = new  Intent();
			intent.setAction(Intent.ACTION_VIEW);
			Uri contentUrl = Uri.parse(url);
			intent.setData(contentUrl);
			//使用这种会导致找不到action的activity时,会提示没有应用可执行操作
			startActivity(Intent.createChooser(intent, "请选择浏览器"));
			//使用这种会导致找不到action的activity时,应用会崩溃
			startActivity(intent);

 

10、listview 滑动会显示一个蓝色滚动条,可能是设置了   android:fastScrollEnabled="true",删除就好了

11、代码混淆之后view设置的onclick中不要使用如if(v == tvcontent),要用if(v.getId() == R.id.tv_content),否则混淆后就无法触发点击事件

 

12、当打开一个xml视图导致开发工具(IDE)直接挂了,那么原因 一:xml的id值自己引用自己,比如自己的id = iv_test,而自身的below = @id/iv_test,导致死循环,这种问题比较容易排查,原因二:可能是自定义的view的代码有死循环,如自己命名重载:setPregress(int p,String text) {this.setprogress()//这是系统的}   重写setPregress(int p){ setPregress(p,"rest")};这就导致死循环,所以xml会直接导致IDE直接死掉;

13、当一个自定义视图首次加载正常显示,但多次进入二级页面在返回,而此时自定义视图越变越小(大)甚至不可见(超出屏幕)时,一定要检查自定义视图的某个字段值是否在重写onMeasure()方法中不断赋值,由于会测量多次导致此值不断变小(大),所以会导致变化-------这个问题搞了一晚上吃亏了

14、4.3以下的设备不支持蓝牙,如果启动蓝牙会导致页面白屏或黑屏,而且系统蓝牙模块直接挂掉,只能重启手机蓝牙才能起来

15、当自定义view时,测量大小后,设置大小时,这个大小不能超过手机屏的大小,即当onmeasure中setMeasureDimension(w,h)中的w或h不能大于手机屏的widthPixel,heightPixel,否则执行onLayout,但不会执行ondraw,即使设置setWillNotDraw(false)也没用

16、RemoteViews:xml的layout不可使用View,自定义view组件或者@demin等,否则会报错:Bad notification posted from package Couldn’t expand RemoteViews

17、.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.PICK typ=image/* (has extras)  }   

    问题是Intent打开相册(或者是Intent传入URI试图打开系统的Activity),由于系统兼容性问题,没找到这个URI对应的Activity就会抛出这个异常

         解决办法:找到官方,URI有没有改动。如果能有最好是兼容,如果找不到官方,只能通过以下判断

         

if (intent.resolveActivity(mActivity.getPackageManager()) != null)
{
    mActivity.startActivityForResult(intent, REQUEST_CODE_ALBUM);
}

         通过Intent找到要打开Activity组件名,才启动。问题解决!!!

 

18.span获取<a>标签中的url最佳方式

if(text instanceof Spannable) {
						int end = text.length();
						Spannable sp = (Spannable) holder.content_tv.getText();
						URLSpan[] urls = sp.getSpans(0, end, URLSpan.class);
						SpannableStringBuilder style = new SpannableStringBuilder(text);
						style.clearSpans();//should clear old spans
						for (final URLSpan url : urls) {

							LMBClickableSpan myURLSpan = new LMBClickableSpan(SkinUtil.getColorByName(SkinColor.red_1)) {
								@Override
								public void onTextClick(View widget) {
									FullScreenWebViewActivity.processCustomUrl(context, url.getURL());
								}
							};
							style.setSpan(myURLSpan, sp.getSpanStart(url), sp.getSpanEnd(url), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
						}
						holder.content_tv.setText(style);
					}

19、scrollview嵌套GridViewView滑动事件冲突:

      当scrollView的高度不超过一屏时,是不会和AbsListView事件冲突的,说以只需要固定scrollView高度,让gridView或ListVIew可滑动。scrollView嵌套gridVIew,解决键盘弹起但却没将布局顶起

也可以使用内部拦截法:重新ScrollView如下

      
DisableScrollView:
 private boolean mDisallowIntercept;
    @Override
    public void requestDisallowInterceptTouchEvent(boolean disallowIntercept) {
        super.requestDisallowInterceptTouchEvent(disallowIntercept);
        Logcat.dLog("disallowIntercept = " + disallowIntercept);
        mDisallowIntercept = disallowIntercept;
    }
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        Logcat.dLog("down 0 up 1 move 2 = " + ev.getAction());
        if (mDisallowIntercept) {//不拦截
            return false;
        }
        return super.onInterceptTouchEvent(ev);
    }

重写GridView:

 @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (null != touchDecision) {
            switch (ev.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    mDownY = ev.getRawY();
                    mDownX = ev.getRawX();
                    touchDecision.isIntercept(true);
                    break;
                case MotionEvent.ACTION_MOVE:
                    dx = Math.abs(ev.getRawX() - mDownX);
                    dy = Math.abs(ev.getRawY() - mDownY);
                    Logcat.dLog("dx " + dx + " dy " + dy + " " + mTouchSlop);
                    if (dy > dx && dy >= mTouchSlop) {
                        touchDecision.isIntercept(true);
                    }

                    break;
                case MotionEvent.ACTION_UP:
                    touchDecision.isIntercept(false);
                    break;
            }
        }
        super.dispatchTouchEvent(ev);
        return true;
    }

    public interface TouchDecision {
        void isIntercept(boolean isIntercept);
    }

    private TouchDecision touchDecision;

    public void setTouchDecision(TouchDecision touchDecision) {
        this.touchDecision = touchDecision;
    }

外部activity关联两个view:

gvPics.setTouchDecision(new ScrollGridView.TouchDecision() {
            @Override
            public void isIntercept(boolean isGridViewIntercept) {//gridView要拦截,则scrollView不拦截~
                //当scrollView的高度不超过一屏时,是不会和AbsListView事件冲突的,可以不需要这个拦截器,但是为了机型以防万一
                scrollView.requestDisallowInterceptTouchEvent(isGridViewIntercept);
            }
        });

 20.android8.0及以上的进程保活,发通知,通过stopservice无法取消通知栏:因为是startForgroundService()会发送一个通知,在通知栏显示,androd8.0后stopService无法取消通知,删除通道,有时会报not found channel或invalid channel,此法不可行,查阅文档后,可通过

//取消通知栏
stopForeground(true);

21.升级至android studio 3.4.1,build3.4.1 gradle5.1.1, 傻逼领导升级我配置,cmake由3.6.4升级至3.10.1,platform-tools升级罪行,导致compiler编译器用不了,无法编译生成相应的类文件。解决办法:将升级的cmake3.10.1删除保留3.6.4,若还是不行,则将platform-tools也降级:都是在sdk 目录下

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值