首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >运动布局-为过渡constraintSetEnd和constraintSetStart使用两个布局文件时,文本大小不会更改

运动布局-为过渡constraintSetEnd和constraintSetStart使用两个布局文件时,文本大小不会更改
EN

Stack Overflow用户
提问于 2020-02-02 11:45:38
回答 1查看 1.1K关注 0票数 0

我有两个布局文件,我用它们来做运动布局的开始和结束过渡。

文本根据开始布局文件到结束布局文件按预期移动。但是,即使在两种布局中定义了不同的文本大小,文本大小也不会改变。

有人能帮帮忙吗?下面提供了这些文件:

motion_layout_start.xml

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<androidx.constraintlayout.motion.widget.MotionLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:showPaths="true">


        <TextView
            android:id="@+id/title"
            android:layout_width="@dimen/match_constraints"
            android:layout_height="wrap_content"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toTopOf="@id/description"
            android:text="HEADING"
            style="@style/TextStyle.Title"
            app:layout_constraintVertical_chainStyle="packed"
            app:layout_constraintVertical_bias="0"/>

        <TextView
            android:id="@+id/description"
            android:layout_width="@dimen/match_constraints"
            android:layout_height="wrap_content"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/title"
            app:layout_constraintBottom_toTopOf="@+id/recycler_view"
            tools:text="DESCRIPTION"
            style="@style/TextStyle.DESC"/>


        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_height="@dimen/match_constraints"
            android:layout_width="match_parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/description"
            app:layout_constraintBottom_toBottomOf="parent" />



    </androidx.constraintlayout.motion.widget.MotionLayout>

motion_layout_end.xml

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<androidx.constraintlayout.motion.widget.MotionLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:showPaths="true">


        <TextView
            android:id="@+id/title"
            android:layout_width="@dimen/match_constraints"
            android:layout_height="wrap_content"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintBottom_toTopOf="@id/recycler_view"
            android:text="HEADING"
            style="@style/TextStyle.SmallTitle"
            app:layout_constraintVertical_chainStyle="packed"
            app:layout_constraintVertical_bias="0"/>


        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_height="@dimen/match_constraints"
            android:layout_width="match_parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/title"
            app:layout_constraintBottom_toBottomOf="parent" />

    </androidx.constraintlayout.motion.widget.MotionLayout>

运动xml文件fragment_motion.xml

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<MotionScene xmlns:app="http://schemas.android.com/apk/res-auto">


    <Transition
        app:constraintSetStart="@layout/motion_layout_start"
        app:constraintSetEnd="@layout/motion_layout_end">

        <OnSwipe app:touchAnchorSide="top"
            app:touchAnchorId="@id/recycler_view"
            app:dragDirection="dragUp"
            app:moveWhenScrollAtTop="true"/>
    </Transition>


</MotionScene>

谢谢

EN

回答 1

Stack Overflow用户

发布于 2020-02-04 00:01:11

虽然在技术上支持在两个ConstraintLayouts之间进行MotionLayout插值,但通过创建自包含的MotionScene可以获得更多功能

上图是一篇非常有用的媒体文章链接here的截图。

为了根据需要更改文本的大小,可以进行一些小的更改,以包含运动场景文件中的大部分功能。请注意,虽然我尽了最大努力根据您给定的代码创建这些文件,但它可能需要一些调整才能在您的代码中正常工作。

首先,创建一个motionLayout文件(您喜欢怎么叫都行,我叫我的motion_layout.xml),如下所示:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<androidx.constraintlayout.motion.widget.MotionLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layoutDescription="@xml/fragment_motion"
    tools:showPaths="true">

    <TextView
        android:id="@+id/title"
        style="@style/TextStyle.Title"
        android:layout_width="@dimen/match_constraints"
        android:layout_height="wrap_content"
        android:text="HEADING" />

    <TextView
        android:id="@+id/description"
        style="@style/TextStyle.DESC"
        android:layout_width="@dimen/match_constraints"
        android:layout_height="wrap_content"
        tools:text="DESCRIPTION" />


    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="@dimen/match_constraints" />

</androidx.constraintlayout.motion.widget.MotionLayout>

这里有一些重要的事情需要注意。首先,注意MotionLayout中的app:layoutDescription="@xml/fragment_motion"。这定义了定义运动的位置。此外,所有约束都已从该文件中剥离。这是因为约束现在将在运动场景中定义。

你需要确保在你的活动中,你膨胀的布局就是上面的动作布局。

接下来,我们需要向MotionScene添加一些约束集。如下所示:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<MotionScene xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <Transition
        app:constraintSetStart="@id/start"
        app:constraintSetEnd="@id/end">

        <OnSwipe app:touchAnchorSide="top"
            app:touchAnchorId="@id/recycler_view"
            app:dragDirection="dragUp"
            app:moveWhenScrollAtTop="true"/>
    </Transition>

    <ConstraintSet
        android:id="@+id/start">
        <Constraint
            android:id="@id/title">
            <Layout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintEnd_toEndOf="parent"/>
            <CustomAttribute
                app:attributeName="textSize"
                app:customFloatValue="24"/>
        </Constraint>

        <Constraint
            android:id="@id/description">
            <Layout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/title"/>
        </Constraint>

        <Constraint
            android:id="@id/recycler_view">
            <Layout
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/description"/>
        </Constraint>

    </ConstraintSet>

    <ConstraintSet
        android:id="@+id/end">
        <Constraint
            android:id="@id/title">
            <Layout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintEnd_toEndOf="parent"/>
            <CustomAttribute
                app:attributeName="textSize"
                app:customFloatValue="14"/>
        </Constraint>

        <Constraint
            android:id="@id/description">
            <Layout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/title"/>
        </Constraint>

        <Constraint
            android:id="@id/recycler_view">
            <Layout
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/description"/>
        </Constraint>
    </ConstraintSet>

</MotionScene>

您会注意到,textSize被设置为标题上的customAttribute。为textSize设置一个浮点值可能看起来很奇怪,但它会在幕后调用setTextSize,当它将其解释为文本时,它将自动应用可缩放像素,这是最佳实践。

如果您有任何问题,请留言。同样,在this blog series中也有一些很好的例子

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60025741

复制
相关文章
为字段设置初始值
在开发中为字段设置初始值这是最基本的要求,但是很多开发人员会在构造函数变多的时候忘记给成员变量设置初始值。为了避免这个问题,我们最好在声明的时候直接初始化,而不是在实现构造函数的时候去初始化。编译器会帮助开发人员在每个构造函数开头放入一段代码,这段代码会把开发人员在定义成员字段时所指定的初始值设置给这些成员字段。如果没有显示定义构造函数,那么编译器就会先创建默认构造函数,之后再向其中加入初始化代码。
喵叔
2020/09/08
1.6K0
文章自定义字段和主题设置字段
在 Typecho 官方的主题开发文档中,很少有关于文章自定义字段和主题设置相关的开发说明。我也是查看了一些开源主题的代码才搞懂自定义字段和主题设置的开发。这里就简单写一下文章自定义字段和主题设置的定义和调用。
怪兽
2022/10/04
1.7K0
文章自定义字段和主题设置字段
ElementUI使用autocomplete组件输入搜索
<el-autocomplete v-model="clientName" :trigger-on-focus="false" highlight-first-item :fetch-suggestions="queryName" @select="getSelect" placeholder="请输入查询姓名"> </el-autocomplete> queryName(queryString, callback) { var queryList = [] //假定list为后台传输的数据
明知山
2020/09/03
1.4K0
腾讯地图 - 关键词输入提示(结尾附视频)
关键词输入提示接口可以用于获取输入关键字的补完与提示,帮助用户快速输入。可以通过配合前端程序实现Autocomplete(自动完成)的效果。
腾讯位置服务
2021/07/14
1K0
腾讯地图 - 关键词输入提示(结尾附视频)
MySQL字段默认值设置详解
在 MySQL 中,我们可以为表字段设置默认值,在表中插入一条新记录时,如果没有为某个字段赋值,系统就会自动为这个字段插入默认值。关于默认值,有些知识还是需要了解的,本篇文章我们一起来学习下字段默认值相关知识。
MySQL技术
2021/03/04
10.5K0
关于 devbridge-autocomplete 插件多选操作的实现方法
目前据我所知最好用的 autocomplete 插件就是 jquery-ui 的 autocomplete 以及 devbridge 的 autocomplete 插件。 我最终选择了 devbridge 的 autocomplete 插件,主要是不想引用 jquery-ui 的 css 文件。 官方网址:https://www.devbridge.com/sourcery/components/jquery-autocomplete/ 先看一下autocomplete的参数 serviceUrl:服务器端
叙帝利
2018/01/17
1.6K0
【分享】在集简云上架应用如何设置动作字段?
字段是用户要在前端填写的内容,可以在应用授权,设置触发/执行动作时都需要设置,字段在开发后台配置后,用户在使用时可在前端看到对应的字段。
集简云
2022/08/26
1K0
【分享】在集简云上架应用如何设置动作字段?
Hive应用:设置字段默认值 原
当我们清理了一些数据之后,数据的某些字段在数据中是没有的但是需要保留这个字段,那么我们将数据插入中转表中时,就需要给这个字段赋予默认值,来让语句正确执行。
云飞扬
2019/03/13
5.2K0
JavaScript实现模糊推荐的input框(类似搜索框)
如何用JS实现一个类似搜索框的输入框呢,再填充完失去焦点时,自动填充配置项,最终效果如下图: 实现很简单,但是易用性会上升一大截,需要用到的有jquery-ui的autocomplete,jquery
用户1225216
2018/03/05
4.5K0
JavaScript实现模糊推荐的input框(类似搜索框)
【分享】在集简云上架应用如何设置动作字段参数?
在开发者平台应用授权和触发/执行字段时都会涉及到字段参数,我们介绍一下各个字段参数的配置。
集简云
2022/08/30
1.1K0
Typecho教程 - 获取模板自定义字段值
在Typecho很多模板都要通过设置自定义字段来实现文章缩略图或者其他功能,但是我们在二次开发或者开发插件时,并没有一个接口来实现获取自定义字段,所以便有了我今天的想法。
用砖头敲代码
2022/08/30
1.6K0
Andorid自定义控件属性值设置
今天写一个简单的自定义控件,实现宽固定,高度根据自定义宽高比例自动调整;或高固定,宽度随比例调整。其中有一个 solid属性,想要像android:layout_width="match_parent" 里的match_parent一样可以输入标记表示一定的意义,这里的solid表示固定的是宽还是高,如:
代码咖啡
2018/08/28
9610
Andorid自定义控件属性值设置
jquery autoComplete 自定义回写样式
   <form:input path="itemName" id="itemName" htmlEscape="false" class="form-control" maxlength="32"                                             data-parsley-required="true" placeholder="请搜索要补录的项目"/>
爱明依
2019/03/12
2.3K0
在 Vue 中创建自定义输入
基于组件的库或框架(如 Vue )可以创建 可重用组件 ,它能在各自应用程序中相互传递数据,这些框架能确保这些数据是一致的,并且(希望)简化了它们的使用方式。
疯狂的技术宅
2019/03/28
6.4K0
MySQL设置字段的默认值为当前系统时间
问题产生: 当我们在对某个字段进行设置时间默认值,该默认值必须是的当前记录的插入时间,那么就将当前系统时间作为该记录创建的时间。 应用场景: 1、在数据表中,要记录每条数据是什么时候创建的,应该由数据库获取当前时间自动记录创建时间。 2、在数据库中,要记录每条数据是什么时候修改的,应该而由数据数据库获取当前时间自动记录修改时间。 实际开发: 记录用户的注册时间、记录用户最后登录时间、记录用户的注销时间等。 实现步骤:(如果使用数据库远程工具则直接设置,更简单!!!) 首先将数据表中字段的数据类型设置为TIM
赵小忠
2018/01/24
9.2K0
WordPress 技巧:在 WordPress 后台隐藏自定义字段
如果你想在写博客的时候保持日志编辑页面尽量的简洁,你可以通过下面的代码把 WordPress 自定义字段隐藏起来。在你主题的 functions.php 文件中添加以下代码:
Denis
2023/04/14
5940
WordPress 技巧:在 WordPress 后台隐藏自定义字段
在 Debian Stretch 上设置自动升级
不少博主,出于安全、稳定的考虑,在自己的服务器上使用了 Debian 操作系统。我们知道,对于多数应用环境,特别是 LNMP 环境,绝大多数安全更新可以自行安装,本文我们将详细介绍,如何在 Debian 环境下自行下载安装最新的系统安全补丁。
Debian中国
2018/12/21
8960
jQuery -- Autocomplete
Autocomplete 顾名思义就是自动完成,在 input 框中输入内容时,将会自动补全符合输入内容的信息。
用户7293182
2022/01/06
1K0
jQuery -- Autocomplete
点击加载更多

相似问题

Jquery AutoComplete在select上设置隐藏输入

10

jQuery-UI AutoComplete不适用于动态字段

11

Jquery-UI禁用输入字段

33

在自定义WooCommerce字段上设置值

17

JSON autocomplete:获取jQuery输入并从单个字段设置多个字段

10
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文