ConstraintLayout:如何从wrap_content计算中排除子项

问题描述 投票:-1回答:1

考虑这个简单的ConstraintLayout content_main.xml,其中一个View是“常规”,而另一个View从概念上讲是动画背景的一部分,但仍相对于常规View进行布局:

<?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"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#000">

    <!--LinearLayout    Fixes 'wrap_content' but breaks positioning
            android:layout_width="0dp"
            android:layout_height="0dp"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"-->

    <View
            android:id="@+id/shouldBeExcludedFromWrapContent"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_marginTop="30dp"
            app:layout_constraintTop_toBottomOf="@id/partOfWrapContent"
            app:layout_constraintLeft_toRightOf="@id/partOfWrapContent"
            android:background="@android:drawable/star_big_on" />

    <!--/LinearLayout-->

    <View
            android:id="@+id/partOfWrapContent"
            android:layout_width="300dp"
            android:layout_height="300dp"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            android:background="@android:drawable/sym_action_call" />

</androidx.constraintlayout.widget.ConstraintLayout>

[C0中带有以下内容:

MainActivity.onCreate()

它产生以下动画( setContentView(R.layout.content_main) findViewById<View>(R.id.shouldBeExcludedFromWrapContent) .animate() .rotationBy(5 * 360f) .translationXBy(-900f) .translationYBy(-900f) .setDuration(5_000L) .start() androidx.constraintlayout:constraintlayout:1.1.3都出现:]

2.0.0-beta4

问题

如何使actual result计算忽略wrap_content?我希望它被其父剪辑,所以最终结果是这样的:

@id/shouldBeExcludedFromWrapContent

注意:

  • [动画视图是通过expected进行布局的[[相对于其同级(上面示例的育儿技巧不是一个选择。在实际代码中,这些关系是复杂得多,无法近似。)

  • ConstraintLayout必须为android:layout_height,因为实际代码将位于wrap_content
  • 接受答案

    必须是

      引用不支持它的权威消息源(例如,对已讨论此问题的ScrollView的官方问题跟踪程序的引用,或ConstraintLayout源代码的引用,或
  • 标题(或等同名称)中提出的问题的解决方案

  • android android-layout android-constraintlayout
    1个回答
    0
    投票
    更新:尝试将最大高度设置为如下所示的约束布局:

    ConstraintLayout

    © www.soinside.com 2019 - 2024. All rights reserved.