如何使用运动布局缩放父视图内的textView?

2023-12-10

我正在尝试缩放容器视图内的 textView 。 Activity 使用运动布局。如果我不将 textView 放置在容器内,我可以缩放它。这是我的活动布局和运动布局描述文件。如何使scaleX和scaleY工作?

活动布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.motion.MotionLayout xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/motionLayout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layoutDescription="@xml/motion_scene_text_size">

    <View
        android:id="@+id/button"
        android:layout_width="64dp"
        android:layout_height="64dp"
        android:background="@color/colorAccent"
        android:text="Button" />

    <android.support.constraint.ConstraintLayout
        android:id="@+id/container"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_marginTop="100dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textSize="20sp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </android.support.constraint.ConstraintLayout>

</android.support.constraint.motion.MotionLayout>

运动场景

<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:motion="http://schemas.android.com/apk/res-auto">

    <Transition
        motion:constraintSetStart="@+id/start"
        motion:constraintSetEnd="@+id/end"
        motion:duration="1000">
        <OnSwipe
            motion:touchAnchorId="@+id/button"
            motion:touchAnchorSide="right"
            motion:dragDirection="dragRight" />
    </Transition>

    <ConstraintSet android:id="@+id/start">
        <Constraint
            android:id="@id/button"
            android:layout_width="64dp"
            android:layout_height="64dp"
            android:layout_marginStart="8dp"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintStart_toStartOf="parent"
            motion:layout_constraintTop_toTopOf="parent" />

        <Constraint
            android:id="@id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textSize="20sp"
            android:scaleX="1.0"
            android:scaleY="1.0"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintStart_toStartOf="parent"
            motion:layout_constraintTop_toTopOf="parent" />

    </ConstraintSet>

    <ConstraintSet android:id="@+id/end">
        <Constraint
            android:id="@id/button"
            android:layout_width="64dp"
            android:layout_height="64dp"
            android:layout_marginEnd="8dp"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintTop_toTopOf="parent" />

        <Constraint
            android:id="@id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:textSize="20sp"
            android:scaleX="2.0"
            android:scaleY="2.0"
            motion:layout_constraintBottom_toBottomOf="parent"
            motion:layout_constraintEnd_toEndOf="parent"
            motion:layout_constraintStart_toStartOf="parent"
            motion:layout_constraintTop_toTopOf="parent" />

    </ConstraintSet>

</MotionScene>

值得注意的是,您只能为 MotionLayout 的直接子级设置动画。

如果你必须使用这个容器,你可以使用matchParent为了height and width你的 TextView 然后使用自动调整文本大小.

<MotionLayout
   ...>

   <ConstraintLayout
    android:id="@+id/container"
    ...>

      <TextView
       android:layout_width="matchParent"
       android:layout_height="matchParent"
       app:autoSizeTextType="uniform"
       app:autoSizeMinTextSize="20sp"
       app:autoSizeMaxTextSize="40sp"
       .../>

   </ConstraintLayout>

</MotionLayout>

在 MotionScene 中,更改 ConstraintLayout 的大小:

<ConstraintSet android:id="@+id/endConstraintSet">

   <Constraint
    android:id="@id/container"
    android:layout_width="200dp"
    android:layout_height="200dp"
    ... />

</ConstraintSet />
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用运动布局缩放父视图内的textView? 的相关文章

  • Whatsapp 在 Android 中共享音频文件时正在剪切音频文件

    我在共享格式不是 mp3 的音频文件时遇到问题 文件被共享 但长度较短 例如 如果文件有 10 秒 则仅共享 5 秒 如果我使用 mp3 格式 它会完全共享 但其他格式会出现问题 注意 该文件在其他应用程序 如Messenger 中共享没有
  • Android,让文本切换器成为中心?

    如何集中我的文本切换器 我尝试过设置重力 但似乎不起作用 ts setFactory new ViewFactory public View makeView TextView t new TextView this t setTypefa
  • 相当于Android中的javax.swing.Timer

    有没有类似的东西javax swing Timer在安卓上 我知道如何创建自己的线程 但是有类似摆动计时器的东西吗 您可能正在寻找课程android os CountDownTimer http developer android com
  • 为网络和/或持久存储序列化 Android Bundle?

    我需要序列化一个全面的应用程序 游戏 状态 以便通过网络传输或保存到磁盘并在以后检索 当然 捆绑包用于在多个用例中保存 恢复状态 因此使用它们将是理想的选择 但是 由于某种原因 Bundle 不可序列化 寻找解决方案只发现了将 Bundle
  • 如何在 android-studio 0.3.6 中运行 Gradle 1.9?

    我只是花了一些时间尝试将现有的 android studio 项目从 gradle 1 8 迁移到 gradle 1 9 Final 昨天发布 但失败了19th Nov 我在这里阅读了大多数其他与 gradle 相关的帖子 但没有一个对我有
  • 注销时Firebase facebook按钮android身份验证

    我在我的 Android 应用程序中使用 firebase 并在 facebook SDK 中使用登录 我面临的唯一问题是 当我使用 facebook 登录然后注销时 facebook 登录按钮处于 注销 状态 当我单击它时 它会询问我是否
  • Android Things 文件系统

    我正在 Android 上构建这个应用程序 我希望能够让它访问 U 盘上的媒体文件 甚至树莓派的 SD 卡上的媒体文件 我还不知道我将如何处理这些文件 但我只是想知道它是否可能 如果不是这样也没关系 我还有其他解决方案 但我想我会先从明显的
  • 将 ArrayList 保存在捆绑包 savingInstanceState 中

    ArrayList 是在类级别定义的 这些是我保存的实例方法 Override protected void onSaveInstanceState Bundle outState super onSaveInstanceState out
  • Android接收通知打开和取消事件

    我从 webService 接收数据以生成自定义通知 我想追踪Intent要知道open 点击 或cancel 滑动 通知上的事件 以报告服务器进行分析 有没有听众onIntentStart or onIntentCanceled 也许是通
  • BluetoothLeScanner 服务内部问题

    Update从Android 10以上我认为你需要ACCESS BACKGROUND LOCATION权限 因此 如果此代码在最新的 Android 版本上不起作用 就是针对此问题的 ACCESS BACKGROUND LOCATION 受
  • ImageButton 拉伸背景图像

    我正在尝试创建一个没有边框的 ImageButton 但遇到了图像按钮大小的问题 我使用 Eclipse ADT 将 ImageButton 拖到布局中并选择背景图像 图像按钮显示如下 正如您所看到的 背景图像和图像按钮周边之间有一个边框
  • 如何使用 onSearchRequested() 调用搜索对话框

    我正在尝试实现搜索对话框 但无法显示活动中的搜索 我在清单文件中定义了主要活动 此活动向用户显示了他们必须从中选择的选项列表 选项之一是 搜索 选项
  • 使用startActivityForResult,如何获取子活动中的requestCode?

    我有四项活动 即 A B C 和 D 我的情况是A将通过startActivityForResult启动活动B startActivityForResult new Intent this B class ONE 在另一种情况下 我将使用不
  • Android apk 调试模式工作正常,但发布模式给出太多警告

    我正在尝试从 eclipse 获取签名的 APK 我有一个可调试的 apk 版本 运行良好 现在发布时 当我尝试使用 Eclipse ADT 进行编译和签名时 我收到很多警告 其中大部分是can t find superclass or i
  • 如何使用asynctask显示倒计时的进度条?

    在我的应用程序中 我希望用户按下按钮 然后等待 5 分钟 我知道这听起来很糟糕 但就这样吧 5 分钟等待期间的剩余时间应显示在进度条中 我使用带有文本视图的 CountDownTimer 来倒计时 但我的老板想要看起来更好的东西 这就是进度
  • 在Android中提取视频帧

    我想知道是否可以从 Android 中正在运行的视频中提取帧 我需要定期提取帧并将其发送以进行进一步处理 有人能为我找到答案吗 Thanks Abhi 您可以使用媒体元数据检索器 http developer android com ref
  • RecyclerView元素更新+异步网络调用

    我有一个按预期工作的回收视图 我的布局中有一个按钮可以填充列表 该按钮应该进行异步调用 根据结果 我更改按钮的外观 这一切都发生得很好 但是 当我单击按钮并快速向下滚动列表时 异步调用的结果会更新新视图的按钮 代替旧视图的视图 我该如何处理
  • SambaFileInputStream 和 FileInputStream 有什么不同?

    我需要从 samba 服务器流式传输视频 并且我使用 nanohttpd 在我的项目中创建简单的服务器 当我使用本地文件中的 fileinputstream 时 视频视图可以按设置播放视频 http localhost 8080 publi
  • android-如何在谷歌地图上将标记的位置显示为地址

    我已经尝试过 commonsware googlemapsv2 教程 特别是在地图上拖动标记 但现在另一个问题困扰着我 问题是如何将标记的当前位置显示为地图下方或上方的地址 字符串 这是我使用的代码 public class MainAct
  • 将 firebase 消息传递添加到 flutter android 项目时出现依赖错误

    我已将 firebase 消息传递添加到我的 Flutter 项目中 在 iOS 上运行良好 在 Android 上运行时出现错误 Android dependency androidx localbroadcastmanager loca

随机推荐