【问题标题】:How to set pivot point for scale animation in MotionLayout如何在 MotionLayout 中设置缩放动画的轴心点
【发布时间】:2020-04-07 02:01:52
【问题描述】:

我正在尝试在动作中设置 pivotX 和 pivotY。

<Constraint android:id="@id/favChatRecyclerView"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:alpha="1"
        android:pivotY="0.0"
        android:pivotX="0.0"
        android:scaleY="1"
        android:scaleX="1"/>

最后一幕:

<Constraint android:id="@id/favChatRecyclerView"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:alpha="1"
        android:pivotY="0.0"
        android:pivotX="0.0"
        android:scaleY="0"
        android:scaleX="0"/>

但看起来枢轴点没有任何效果。我仍然在视图中心获得带有枢轴的缩放动画。有什么办法可以解决吗?

【问题讨论】:

  • 您是否尝试过在视图本身上设置android:transformPivotXandroid:transformPivotY 属性?

标签: android android-constraintlayout android-motionlayout


【解决方案1】:

我找到了在滑动期间更改文本大小的解决方案,但我想您可以将相同的方法应用于一般的运动布局过渡。这是我的场景描述:

<Transition
    motion:constraintSetStart="@+id/start"
    motion:constraintSetEnd="@+id/end"
    motion:duration="1000">
    <OnSwipe
        motion:touchAnchorId="@+id/wv_file_content"
        motion:touchRegionId="@+id/v_web_view_touch_region"
        motion:touchAnchorSide="bottom"
        motion:dragDirection="dragUp" />

    <KeyFrameSet>
        <KeyAttribute
            android:scaleX="1.5"
            android:scaleY="1.5"
            motion:framePosition="100"
            motion:motionTarget="@+id/TEXTVIEW"
            />
    </KeyFrameSet>
</Transition>

到目前为止,这是您已经想到的。你不能像你问的那样直接在场景描述中设置轴心点,但是你可以像@vitalnik描述的那样在原始layout.xml中间接设置它。

以下要直接在layout.xml中设置!不在场景描述 xml 中。

 <TextView
    android:id="@+id/TEXTVIEW"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:transformPivotX="0sp"
    android:transformPivotY="9sp" />

这将以缩放保持文本左对齐的方式设置枢轴点。 我是怎么想到 9sp 的?我从here得到了这个计算

在缩放模式下等于文本视图大小的 1/2 (in sp)

原来我的 TextView 12sp。按因子 1.5 缩放意味着它在缩放模式下为 18sp。 其中一半是 9sp,这是我用于 android:transformPivotY

的值

使用这种计算方法,您还可以保持正确对齐或任何您想要的。

【讨论】:

    猜你喜欢
    • 2013-06-06
    • 1970-01-01
    • 1970-01-01
    • 2016-12-13
    • 2018-01-14
    • 2018-05-30
    • 1970-01-01
    • 1970-01-01
    • 2013-02-12
    相关资源
    最近更新 更多