我设计了一个自定义小部件的布局。在自定义小部件内,我有一个要出现和消失的视图。可见性也将影响其他需要过渡的布局。但是,这没有发生。它突然移动。在下面发布代码段。下面的代码段以及其他视图位于ScrollView内部。
带有窗口小部件的主布局:
<LinearLayout
android:id="@+id/parentLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical">
<SlotWidget
android:id="@+id/widgetMorning"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:scheduleIcon="@drawable/ic_morning"
app:scheduleLabel="@string/morning" />
<SlotWidget
android:id="@+id/widgetNoon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:scheduleIcon="@drawable/ic_noon"
android:animateLayoutChanges="true"
app:scheduleLabel="@string/noon" />
<SlotWidget
android:id="@+id/widgetAfterNoon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:scheduleIcon="@drawable/ic_afternoon"
android:animateLayoutChanges="true"
app:scheduleLabel="@string/afternoon" />
<SlotWidget
android:id="@+id/widgetNight"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:animateLayoutChanges="true"
app:scheduleIcon="@drawable/ic_night"
app:scheduleLabel="@string/night" />
</LinearLayout>
小部件布局:
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/parentLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true">
<androidx.cardview.widget.CardView
android:id="@+id/cardHeading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_16dp"
android:layout_marginRight="@dimen/margin_16dp"
android:filterTouchesWhenObscured="true"
android:foreground="?attr/selectableItemBackgroundBorderless"
app:cardCornerRadius="4dp"
app:cardUseCompatPadding="true"
app:elevation="4dp"
android:animateLayoutChanges="true"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layoutScheduleHead"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:paddingLeft="@dimen/margin_16dp"
android:paddingTop="@dimen/margin_5dp"
android:paddingBottom="@dimen/margin_5dp">
<ImageView
android:id="@+id/ivSchedule"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/ic_morning"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/margin_16dp"
android:src="@drawable/ic_arrow_down_filled"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvScheduleName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_16dp"
android:text="@string/morning"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@id/ivSchedule"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/layoutSlot"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
<View
android:id="@+id/view1"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#dfdfdf"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.chip.ChipGroup
android:id="@+id/chipGroupSlots"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/margin_16dp"
android:paddingTop="@dimen/margin_16dp"
android:paddingRight="@dimen/margin_16dp"
android:paddingBottom="@dimen/margin_16dp"
app:singleSelection="true"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/view1"
app:layout_constraintRight_toRightOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>