最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Android: Multiple views occupying same location in layout - how? - Stack Overflow

programmeradmin4浏览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=";
    xmlns:app=";
    xmlns: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>
发布评论

评论列表(0)

  1. 暂无评论