问题标签 [constraintset]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
768 浏览

java - 使用 ConstraintSet 时测量的布局大小为零

这真让我抓狂!当我尝试使用约束布局和约束集以编程方式构建布局时,测量的布局始终为 0。

我对所有孩子和父母都试过了requestLayout。但宽度和高度为 0,使整个视图不可见。forceLayoutinvalidate

这是我的布局生成器。我的问题是当我应用约束时视图呈现不可见。


MainActivity.java


窗体视图.java


main_activity.xml

0 投票
1 回答
644 浏览

android - 在 BottomSheetFragment 上重复 ConstraintSet 的过渡动画问题

我想在单击时为 BottomSheetFragment 上的布局更改设置动画。我实现了 ConstraintSet.applyTo 和 TransitionManager.beginDelayedTransition 以将初始场景更改为最终场景。但是当过渡发生时,动画似乎在重复。底部的示例输出。

BottomSheetFragment.java

bottom_sheet_filter_leave.xml

layout_bottom_date_filed.xml

这是它的样子:

在此处输入图像描述

更新:

我尝试将此设置应用于其他片段(不是 BottomSheetFragment),动画似乎工作正常。也许它与BottomSheetFragment有关?

0 投票
1 回答
2249 浏览

android - 来自 ConstraintSet 的 clone 和 applyTo 使应用程序崩溃

我正在尝试为以编程方式创建的 ImageView 创建一些约束,但是当我运行该应用程序时,它会崩溃(不幸的是,pruebaConstraint 已停止。消息)。正如标题所说,当我添加行 cs.clone(constraintLayout) o cs.applyTo(constraintLayout) 时发生崩溃。我尝试了几种变体,但没有任何效果。我被困在这里,不知道还能做什么。我想这与在 XML 文件中创建的对象有关。

活动主.xml:

MainActivity.java:

据我了解,我需要克隆布局(在本例中为 parentLayout)以便将约束集添加到 ImageView infinito。

顺便说一句,ImageView 对象 infinito 在通过代码创建时被渲染(在屏幕中以其默认位置出现)并且尚未创建约束。

更新:如果我在 XML 文件中创建 ImageView 对象,

工作正常,并且ImageView设置在位置约束指示中。

0 投票
0 回答
591 浏览

android - 使用 ConstraintSet 的 ConstraintLayout 动画不适用于 ScrollView

我有两个带有 ConstraintLayout 的布局,其中有一个子 NestedScrollview 和 NestedScrollview 有一个子 ConstraintLayout 再次作为容器而不是其他视图。我想使用 ConstraintSet 为两个布局设置动画,但不幸的是,这不起作用。另一方面,如果我删除 NestedScrollview 和根 ConstraintLayout 那么它工作正常。我想用 NestedScrollview 或 Scroll view 来完成这个任务,这可能吗?提前致谢。这是我的代码

活动登录.xml

activity_login_detial.xml

登录活动.java

0 投票
1 回答
812 浏览

android - Recycler View 中的约束设置动画未正确设置动画

我正在为我的回收站视图项使用约束布局。要为它们设置动画(展开/折叠),我使用约束集动画。开场动画在所有项目上运行良好。关闭动画也运行良好,但是当关闭动画在不是最后一个的项目上开始时,所有项目都会在动画开始时跳跃,而不是在动画结束时。

动画在项目点击时执行:

animateItemView 在哪里:

day_of_week.xml(扩展)布局:

和 day_of_week_small.xml(折叠)布局:

这里有什么问题,我该如何解决?谢谢你。

动画示例:

https://gph.is/g/aj8GdB4

0 投票
0 回答
86 浏览

android - RecyclerView ViewHolder 中的 beginDelayedTransiton 被忽略

我正在尝试RecyclerView使用动画为项目设置ConstraintSet动画。我有两种布局,它们使用以下代码正确切换:

但是延迟转换被完全忽略,无论我是否添加beginDelayedTransition代码,它的工作方式都是一样的,所以没有动画。

0 投票
2 回答
772 浏览

android - recyclerview viewholder布局中的更改约束 - android

我正在开发聊天应用程序,所以我希望有时间TextView像什么应用程序一样,它的约束可以根据文本而改变

所以我在消息布局中尝试了视图树观察器,它以某种方式工作,但缺少一些东西

这是我的布局 xml

问题是,当我打开现有聊天时,第一个图像出现的约束在长消息中没有按预期工作,但是一旦我点击输入消息编辑文本,屏幕聊天的约束就改变了,而不是所有的聊天,所以如果我滚动屏幕上的聊天约束,除非我点击输入消息编辑文本等,否则不会改变。

我是否缺少侦听器或请求焦点或其他内容或缺少什么

这是图片一 https://i.stack.imgur.com/lBdEl.png

这里是图二 在此处输入图像描述

0 投票
1 回答
307 浏览

android - Programmatically add Button to ConstrainLayout with ConstraintSet

GoodDay everyone.

Im trying to add a button programmatically to a ConstraintLayout and set ConstraintSet to such button. The problem comes when I try to close the constraintSet from the layout as the button I've added has no ID.

This is the generated error on the console:

I would like to avoid assigning a random number to the button as ID as it's created in a loop. Any idea how to fix this?

0 投票
1 回答
2857 浏览

android - ConstraintLayout that should support portrait and landscape modes -with a button to toggle full screen

I'm trying to achieve the 4 cases of the image but with no success. Orange square is 40dp and used to toggle full screen. As you can see, in portrait\landscape mode: when orange button is pressed, the screen is toggled between 2 cases. Just take in mind that I can turn the smartphone back to portrait\landscape all the time and thus I think that the xml constraints are not really necessary.

I've tried this code but it doesn't work:

Here is the xml I use (not sure if relevant because I override it in code)

Please help me to achieve the desired result.

enter image description here

0 投票
1 回答
1244 浏览

android - 以编程方式修改 ConstraintSet 链未按预期工作

由于某种原因,当以编程方式修改 aConstraintLayoutConstraintSet更改视图位置(属于链)时,结果与预期不符。

在下面的示例中,我构建了一个带有图标视图的按钮,其中图像可以位于按钮的开头或结尾。当图标位于末尾时,一切都很好。但是当它被设置在按钮的开头时,它的内容会无缘无故地向左对齐。

我不知道如何解决这个问题。我已经在代码中尝试了几处修改,但都没有奏效。

如何解决?


将图标设置为位于按钮开头时的错误行为

将图标设置为位于按钮开头时的错误行为。它以某种方式与按钮的左侧对齐


ButtonWithIconView.kt


button_with_icon_view.xml


attrs.xml


activity_main.xml