- 设计稿如下:
![](https://i-blog.csdnimg.cn/blog_migrate/cc16eb93b788526a7384b9ad8d6ff535.png)
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<TextView
android:id="@+id/tv_wrong_sm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="[sat]"
android:textStyle="bold"
android:layout_marginTop="20dp"
android:textColor="#ff383838"
android:gravity="center"
android:textSize="25sp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@id/tv_right_sm"
/>
<ImageView
android:id="@+id/iv_wrong"
app:layout_constraintTop_toBottomOf="@id/tv_wrong_sm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_wrong_sound"
android:layout_marginTop="16dp"
app:layout_constraintLeft_toLeftOf="@id/tv_wrong_sm"
app:layout_constraintRight_toRightOf="@id/tv_wrong_sm"
/>
<TextView
android:id="@+id/tv_right_sm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="[seit]"
android:textStyle="bold"
android:layout_marginTop="20dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toRightOf="@id/tv_wrong_sm"
android:textColor="#ff383838"
android:gravity="center"
android:textSize="25sp"
/>
<ImageView
app:layout_constraintTop_toBottomOf="@id/tv_right_sm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/icon_right_sound"
android:layout_marginTop="16dp"
app:layout_constraintLeft_toLeftOf="@id/tv_right_sm"
app:layout_constraintRight_toRightOf="@id/tv_right_sm"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
左侧隐藏,只需要:
findViewById(R.id.tv_wrong_sm).setVisibility(View.GONE);
findViewById(R.id.iv_wrong).setVisibility(View.GONE);
隐藏后仍然是居中效果: