-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
父布局为ConstraintLayout时报错 #15
Comments
另外大佬什么时间能修复呢?公司项目,否则我得copy源码,本地打包才能使用了。 |
StateView 版本是多少?还有布局层次是 stateView.inject(ConstraintLayout) ? 还是其它情况,代码贴一下会更好找到问题,我这边 inject ConstraintLayout 是没有问题的 |
我按照你指定的代码试着重现了下,确实是兼容有问题,发现 ConstraintLayout 的 remove 方法里 public void onViewRemoved(View view) {
if (android.os.Build.VERSION.SDK_INT >= 14) {
super.onViewRemoved(view);
}
this.mChildrenByIds.remove(view.getId());
ConstraintWidget widget = this.getViewWidget(view); // 有widget 的存在,还需要转换再 remove
this.mLayoutWidget.remove(widget);
this.mConstraintHelpers.remove(view);
this.mVariableDimensionsWidgets.remove(widget);
this.mDirtyHierarchy = true;
} public final ConstraintWidget getViewWidget(View view) {
if (view == this) {
return this.mLayoutWidget;
} else {
return view == null ? null : ((ConstraintLayout.LayoutParams)view.getLayoutParams()).widget;
}
} 之后我会发个版本 |
最新版本; |
之后又抛出什么问题了?你说一下,我这边试着复现一下 |
cl移除了rv,但是cl在layout的时候通过bottomToTop这个id又找到了Rv(其实rv的children 即SparseArray<View
|
下班了,没有复现的环境,明天我给您一个复现场景和异常栈 |
重现环境: ConstraintLayout.java:1144(从源码上看,有别的控件约束于Rv(aka: injectedView)时,就会出错。Rv加入到FrameLayout,变成了FrameLayout.LayoutParams,getTargetWidget中cast 就又错了) 具体: java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams cannot be cast to android.support.constraint.ConstraintLayout$LayoutParams |
布局发一下 |
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
</android.support.constraint.ConstraintLayout> margin、bg、style等请忽略 |
没复现出来 <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/constraint_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.github.nukc.sample.ConstraintLayoutActivity">
<TextView
android:id="@+id/text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="顶部"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="spread" />
<EditText
android:id="@+id/et_remark"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="12dp"
android:gravity="left|top"
app:layout_constraintBottom_toTopOf="@+id/recycler_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/text"
app:layout_constraintVertical_weight="1" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="12dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="12dp"
app:layout_constraintBottom_toTopOf="@id/btn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/et_remark"
app:layout_constraintVertical_weight="2" />
<Button
android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout> mStateView = StateView.inject(findViewById(R.id.recycler_view)); |
代码中是这样注入的, tartgetView即Rv,不介意的话能QQ(1018498538)上交流吗,这样效率慢了点。
} |
Thanks. |
172行左右
源代码
FrameLayout root = new FrameLayout(parent.getContext());
root.setLayoutParams(parent.getLayoutParams());
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
parent.setLayoutParams(layoutParams);
应该改为
FrameLayout root = new FrameLayout(parent.getContext());
root.setLayoutParams(parent.getLayoutParams());
在rootGroup.removeView(parent);之前设置parent.setLayoutParams(layoutParams);会导致remove时viewGroup cast 错误
The text was updated successfully, but these errors were encountered: