0

I have a layout in which three checkboxes are all located at the same position. Only one of the checkboxes is enabled and visible at a time, depending on other parameters. I'm getting a "cb_xxx <Checkbox> is covered by cb_yyy <Checkbox>" warning because they both occupy the same space, which is understandable.

I know I can just disable or ignore the warning, but it got me wondering if there's a better way to do what I want to do. Thanks!

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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/main"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".MyActivity"
    >

    <CheckBox
        android:id="@+id/cb_type1"
        android:text="Type1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:ignore="HardcodedText"
        />

    <CheckBox
        android:id="@+id/cb_type2"
        android:text="Type2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:ignore="HardcodedText"
        />

    <CheckBox
        android:id="@+id/cb_type3"
        android:text="Type3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:ignore="HardcodedText"
        />

</androidx.constraintlayout.widget.ConstraintLayout>
1
  • I'd suggest to use only one Checkbox and set values programmatically. Or use ViewFlipper which shows only one view at the time. Commented Jan 20 at 19:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.