你可以按照这个方法
XML文件
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/clMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent">
<ImageView
android:id="@+id/ivDone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:src="@drawable/ic_done_black_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="@+id/tvShipInBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="Ship in Box($10 Extra per box)"
android:textColor="#E83535"
app:layout_constraintBottom_toBottomOf="@id/ivDone"
app:layout_constraintStart_toEndOf="@id/ivDone" />
<ImageView
android:id="@+id/ivInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:src="@drawable/ic_info_black_24dp"
app:layout_constraintBottom_toBottomOf="@id/ivDone"
app:layout_constraintStart_toEndOf="@id/tvShipInBox" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/clToolTip"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:background="@drawable/ic_tooltip_bg"
app:layout_constraintBottom_toTopOf="@id/clMain"
app:layout_constraintHeight_percent="0.075"
app:layout_constraintStart_toStartOf="@id/clMain"
app:layout_constraintWidth_percent="0.65">
<TextView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginHorizontal="8dp"
android:alpha="0.87"
android:text="A box increases an items volumetric weight and costs more."
android:textColor="#000000"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent="0.6"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Java文件
public class MainActivity extends AppCompatActivity {
ImageView ivInfo;
ConstraintLayout clToolTip;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ivInfo = findViewById(R.id.ivInfo);
clToolTip = findViewById(R.id.clToolTip);
ivInfo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ivInfo.setVisibility(View.INVISIBLE);
ivInfo.postDelayed(new Runnable() {
public void run() {
clToolTip.setVisibility(View.VISIBLE);
}
}, 7000);
}
});
}
}