在一个项目中,我设置了控件的invisible特性,
最初的时候,我在全局的ConstraintLayout下面写了textView,可以顺利实现控件的显示和隐藏
后来把textView用了一个ContraintLayout包裹一层,
<android.support.constraint.ConstraintLayout
android:id="@+id/controller_view"
android:layout_width="match_parent"
android:layout_height="@dimen/camera_controller_height"
android:background="@drawable/camera_controller_bg"
android:clickable="true"
android:padding="6dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent">
<android.support.constraint.ConstraintLayout
android:id="@+id/controller_viewpoint"
android:layout_width="match_parent"
android:layout_height="47dp"
android:layout_marginLeft="84dp"
android:layout_marginTop="14dp"
android:layout_marginRight="33dp"
android:visibility="gone"
android:background="@mipmap/ic_controller_viewpoint_background"
android:overScrollMode="never"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="parent">
<TextView
android:id="@+id/tv_point1"
android:layout_width="wrap_content"
android:layout_height="24dp"
android:layout_marginLeft="6dp"
android:background="@drawable/camera_bg_selecte_blue"
android:gravity="center"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:text="低吸高抛"
android:textColor="@color/camera_select_color"
android:textSize="@dimen/camera_small_size"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
当我使用viewpoint.visible = View.GONE 的时候,下面的textView不能完全消失,会留下一个背景小圆圈。
后来我发现,是因为我使用
fullControllerViewSet.setVisibility(view.id, view.visibility)
这行代码,把这个textView和最外层的约束性布局ContraintLayout绑定在一起,由于后来又包裹了一层,这个绑定关系就消失了。当我使用viewpoint.visible = View.GONE的时候,viewpoint布局下面的textview不会起作用。
必须给textview设置invisible属性
tv_point1.visibility = View.INVISIBLE
细节问题,必须注意。