我当前要执行的操作是更改视图的约束,如果它接触到屏幕的边缘,即将其约束到父视图的左侧和上一行视图的底部。当我尝试执行此操作时,该行中的第一个视图消失了,但是,其余视图(仅限于消失的视图)按预期出现。有人遇到过这个问题吗?我该如何解决?
如果我从textView中清除了TOP约束,则它连同其后的所有textViews一起消失。如果我在重置约束之前没有删除约束,则将出现第一个textView,但是所有视图都会在屏幕的梯子中滑动,直到最终所有视图都在屏幕外部创建为止。之所以这样做,是因为默认情况下第一个视图被限制为上一行中最后一个视图的底部。
//this code is executed when textViews[finalI] hits the edge of the screen
// constraintSet.clear(textViews[finalI].getId(),
ConstraintSet.LEFT);
// uncommenting the above line will result in desired rows with
first components missing
// constraintSet.clear(textViews[finalI].getId(),
ConstraintSet.TOP);
// uncommeting both results in textviews complete disappearing
constraintSet.connect(textViews[finalI].getId(),
ConstraintSet.TOP, textViews[mRowBeginningId].getId(),
ConstraintSet.BOTTOM);
constraintSet.connect(textViews[finalI].getId(),
ConstraintSet.RIGHT, mConstraintLayout.getId(),
ConstraintSet.LEFT);
constraintSet.applyTo(mConstraintLayout);
mRowBeginningId = finalI;
mCurrentLineLength=textViews[finalI].getMeasuredWidth();
//below is the code for the initial constraining process
if (i==0) { //first word gets constrained to top-left of constraintLayout
constraintSet = new ConstraintSet();
constraintSet.clone(mConstraintLayout);
//constraintSet.clear(textViews[i].getId());
constraintSet.connect(textViews[i].getId(), ConstraintSet.TOP,
mConstraintLayout.getId(), ConstraintSet.TOP);
constraintSet.connect(textViews[i].getId(), ConstraintSet.RIGHT,
mConstraintLayout.getId(), ConstraintSet.LEFT);
constraintSet.applyTo(mConstraintLayout);
} else { //other words get constrained to previous ones.
constraintSet = new ConstraintSet();
constraintSet.clone(mConstraintLayout);
constraintSet.connect(textViews[i].getId(), ConstraintSet.LEFT,
textViews[i - 1].getId(), ConstraintSet.RIGHT);
constraintSet.connect(textViews[i].getId(), ConstraintSet.TOP,
textViews[i - 1].getId(), ConstraintSet.TOP);
constraintSet.applyTo(mConstraintLayout);
}