有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何使用视图处理水平和垂直约束。跑了

已在约束中使用垂直和水平链以实现控制柄可见性。但是他们不适合我想做的事情。 我需要设置如下示例中的视图:

1 2
3 4
5 6 

举个例子,当我将数字2设置为“可见性消失”时,数字3必须取代他的位置

我试着做这样的事,但我还差一点

`<安卓x.constraintlayout.widget.ConstraintLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    xmlns:app="http://schemas.安卓.com/apk/res-auto"
    安卓:layout_width="match_parent"
    安卓:layout_height="match_parent"
    安卓:orientation="vertical">


    <安卓x.constraintlayout.widget.ConstraintLayout
        安卓:id="@+id/paymentCardQR"
        安卓:layout_width="100dp"
        安卓:layout_height="100dp"
        安卓:background="@color/green"
        app:layout_constraintBottom_toTopOf="@+id/paymentCardEfectivo"
        app:layout_constraintEnd_toStartOf="@+id/paymentCardTarjeta"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintHorizontal_chainStyle="packed"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_chainStyle="packed">

    </安卓x.constraintlayout.widget.ConstraintLayout>

    <安卓x.constraintlayout.widget.ConstraintLayout
        安卓:id="@+id/paymentCardEfectivo"
        安卓:layout_width="100dp"
        安卓:layout_height="100dp"
        安卓:background="@color/red"
        app:layout_constraintBottom_toTopOf="@+id/paymentCardCtaCliente"
        app:layout_constraintEnd_toStartOf="@+id/paymentCardVoucher"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintHorizontal_chainStyle="packed"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/paymentCardQR">

    </安卓x.constraintlayout.widget.ConstraintLayout>

    <安卓x.constraintlayout.widget.ConstraintLayout
        安卓:id="@+id/paymentCardCtaCliente"
        安卓:layout_width="100dp"
        安卓:layout_height="100dp"
        安卓:background="@color/green"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/paymentCardOnline"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintHorizontal_chainStyle="packed"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/paymentCardEfectivo">

    </安卓x.constraintlayout.widget.ConstraintLayout>

    <安卓x.constraintlayout.widget.ConstraintLayout
        安卓:id="@+id/paymentCardTarjeta"
        安卓:layout_width="100dp"
        安卓:layout_height="100dp"
        安卓:background="@color/gray"
        app:layout_constraintBottom_toTopOf="@+id/paymentCardVoucher"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/paymentCardQR"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_chainStyle="packed">

    </安卓x.constraintlayout.widget.ConstraintLayout>

    <安卓x.constraintlayout.widget.ConstraintLayout
        安卓:id="@+id/paymentCardVoucher"
        安卓:layout_width="100dp"
        安卓:layout_height="100dp"
        安卓:background="@color/blue"
        app:layout_constraintBottom_toTopOf="@+id/paymentCardOnline"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/paymentCardEfectivo"
        app:layout_constraintTop_toBottomOf="@+id/paymentCardTarjeta">

    </安卓x.constraintlayout.widget.ConstraintLayout>

    <安卓x.constraintlayout.widget.ConstraintLayout
        安卓:id="@+id/paymentCardOnline"
        安卓:layout_width="100dp"
        安卓:layout_height="100dp"
        安卓:background="@color/black"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toEndOf="@+id/paymentCardCtaCliente"
        app:layout_constraintTop_toBottomOf="@+id/paymentCardVoucher">

    </安卓x.constraintlayout.widget.ConstraintLayout>


</安卓x.constraintlayout.widget.ConstraintLayout>

共 (1) 个答案

  1. # 1 楼答案

    这不适用于ConstraintLayout我担心,您应该在一个单独的项目中对每个视图使用RecyclerView,同时使用GridLayoutManager作为其具有两个跨距的布局管理器

    创建列表时,可以通过其适配器控制项目的数量,使用notifyItemRemoved(1)移除或notifyItemInserted(1)通过动画平滑地添加项目。或者,在更改数据集后,您可以轻松地调用notifyDataSetChanged()进行完整但没有性能的适配器更新