取消设置 Flex 组件的显式高度值?

发布于 2024-10-26 09:18:52 字数 180 浏览 1 评论 0原文

当在没有设置特定高度值的情况下声明容器组件时,容器的高度将自动设置为一个值,该值可以在不滚动的情况下显示其所有内容/子组件(如果可能)。

使用正确的高度初始化组件后,我显式更改容器的高度值。

我的问题是,更改组件的高度后,是否可以切换回根据容器内容自动设置的原始高度?我正在寻找某种方法来取消设置组件高度的显式值。

When a container component is declared without setting an specific height value, the contaniner's height will be automatically set to a value which makes possible to display all of its content/children without scrolling (when possible).

After the component is initialized with the proper height, I explicitly change the height value of the container.

My question is, after I change the component's height, is it possible to switch back to the original height that was automatically set based on the containers contents? I'm looking for some way to unset the explicit value of the component's height.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

找回味觉 2024-11-02 09:18:52

一个可能对您有用的技巧是将高度设置为“NaN”,这会有效地“取消设置”您之前设置的显式值。

One trick that may be useful for you is to set the height to "NaN", which effectively "unsets" the explicit value you set earlier.

我的黑色迷你裙 2024-11-02 09:18:52

如果在手动更改之前不存储原始高度,我认为这是不可能的。

您可以做的是扩展您用作容器的基础对象,以添加一个名为 OriginalHeight 的新属性(也可以添加 OriginalWidth)。

然后,您可以重写 set height 函数,以便在更改之前将原始高度存储在新的 OriginalHeight 属性中。当您需要将其设置回来时,只需设置容器的height = OriginalHeight即可。

Without storing the original height before it was manually changed, I don't believe this is possible.

What you could do is extend whichever base object you're using as a container to add a new property called OriginalHeight (might as well add OriginalWidth while you're there).

Then you would override the set height function to store the original height in your new OriginalHeight property before it gets changed. When you need to set it back, you would just set the container's height = OriginalHeight.

一影成城 2024-11-02 09:18:52

容器的高度为
自动设置一个值

这并不是完全自动的。组件总是会设置子组件的高度和宽度;但它永远无法设置自身的高度和宽度。它只能提出建议(通过设置measuredHeight和measuredWidth属性来使用measure方法)。父容器是否要使用或忽略这些测量高度/测量宽度值取决于父容器。

Flex 框架容器都编写了用于计算高度/宽度/定位的代码。如果你正在使用这些,它可能看起来是自动的;但这实际上是一个相当手动的过程。您只是使用别人编写的代码。

如果显式更改容器的高度值,该怎么做?在容器内(this.height = newvalue)?或者父级是否以某种方式改变高度(myContainer.height=newValue)?

除此之外,这取决于原始高度值是多少。您可以使用测量的高度值,但我不会指望它。不过,如果您指定绝对高度和绝对宽度,则永远不会运行测量。

杰森关于存储旧值的答案可能是最好的答案。

contaniner's height will be
automatically set to a value

This is not quite automatic. A component will always set the height and width of children; but it can never set the height and width of itself. It can only make suggestions (using the measure method by setting the measuredHeight and measuredWidth property). It is up to the parent container whether it wants to use or ignore those measuredHeight / measuredWidth values.

The Flex Framework containers all have code written for calculating height / width / positioning. IF you are using those, it may seem automatic; but it is actually a fairly manual process. You're just using code someone else wrote.

If you explicitly change the height value of the container, how do you do it? Inside the container (this.height = newvalue ) ? Or does the parent somehow change the height (myContainer.height=newValue)?

Beyond that, it depends what the original height value was. It is possible you can use the measuredHeight value, but I wouldn't count on it. Although, if you are specifying absolute height and absolute width then measure will never be run.

Probably Jason's answer about storing the old value is the best one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文