QMUI_Android icon indicating copy to clipboard operation
QMUI_Android copied to clipboard

QMUIFloatLayout addview() 数组越界问题

Open BestCoderXQX opened this issue 5 years ago • 2 comments

请尽量详细地提供以下信息:

  • 该 QMUIFloatLayout 是在什么宽高限制下布局的?
  • 该 QMUIFloatLayout 的使用方法(maxNumber、maxLines、horizontalSpacing 等属性)
  • 该 QMUIFloatLayout 的子 View 的情况(数量,各个子 View 的宽高信息)

最好能提供一份导致该异常的布局 xml 或动态添加子 View 的代码。谢谢

Originally posted by @chanthuang in https://github.com/Tencent/QMUI_Android/issues/545#issuecomment-475182407

BestCoderXQX avatar Feb 05 '20 09:02 BestCoderXQX

xml : <com.qmuiteam.qmui.widget.QMUIFloatLayout android:id="@+id/qm_float_size" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingRight="5dp" android:paddingLeft="@dimen/dp_60" app:qmui_childHorizontalSpacing="10dp" app:qmui_childVerticalSpacing="8dp" android:paddingTop="15dp" app:layout_constraintLeft_toRightOf="@+id/specification_title" />

java: qm_float_color = headerView.findViewById(R.id.qm_float_color); qm_float_color.setGravity(Gravity.LEFT); qm_float_color.setClickable(true); TextView tv_item = (TextView) LayoutInflater.from(mContext).inflate(R.layout.item_expend_color_specification, null); qm_float_color.addView(tv_item);

出现数组越界问题: E/CrashReport: # RUNTIME TOTAL RAM:5905682432 ROM:119450603520 SD:119450603520 # CRASH STACK: java.lang.ArrayIndexOutOfBoundsException: length=1; index=1 at com.qmuiteam.qmui.widget.QMUIFloatLayout.onMeasure(QMUIFloatLayout.java:153) at android.view.View.measure(View.java:23223) at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:1028)

BestCoderXQX avatar Feb 05 '20 09:02 BestCoderXQX

目前我定位到的现象是,QMUIFloatLayout放在约束布局里面,宽度充满父布局(0或者match)的时候会出现这个问题,应该是在约束布局中对控件的宽度计算有些问题(获取到的宽度为0?行数计算错误?)。目前给QMUIFloatLayout随便增加一个最小宽度(layout_constraintWidth_min)可以暂时避免这个问题。

moon2star avatar Sep 13 '21 04:09 moon2star