简体   繁体   English

在Android版面中无法使子视图比父视图更宽

[英]Unable to make child view wider than parent in Android Layout

I'm moving a view after an animation completes(to slide out a menu from the left). 我在动画完成后移动视图(从左侧滑出菜单)。 However, I don't seem to be able to achieve the effect I'm looking for. 但是,我似乎无法达到我想要的效果。 What I'd like is for the view to extend to the right past the parent's bounds, like this: 我想要的是视图延伸到父节点的右边,如下所示:

我想要的是

but what's happening is actually this: 但是发生了什么事实上是这样的:

实际结果

The view resets itself to stay within the bounds of the parent. 视图重置自身以保持在父级的范围内。 Even if I set an absolute pixel value (by looking at the display's width, or even a randomly large value). 即使我设置了绝对像素值(通过查看显示器的宽度,甚至是随机大的值)。

The reason I need to do this is detailed in this SO question about a view's actual position after an animation has completed: TranslateAnimated ImageView not clickable after animation [Android] 我需要这样做的原因在这个关于视图在动画完成后的实际位置的问题中详细说明: TranslateAnimated ImageView在动画之后无法点击[Android]

any thoughts? 有什么想法吗? Thanks! 谢谢!

So, here is a related question . 所以,这是一个相关的问题 It explains how to move a view out of the screen. 它解释了如何将视图移出屏幕。

I had same problem and I found the solution. 我有同样的问题,我找到了解决方案。 I hope it can be helpful. 我希望它会有所帮助。 You need to set fixed width if you want to achieve this effect. 如果要实现此效果,则需要设置固定宽度。 To find real width of the view you need to measure it. 要查找视图的实际宽度,您需要测量它。 So full solution is: 完全解决方案是:

view.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
int height = view.getMeasuredHeight();
int width = view.getMeasuredWidth();
view.setLayoutParams(new LinearLayout.LayoutParams(width, height));

(Use LayoutParams of the type corresponding the type of the parent layout) (使用与父布局类型对应的类型的LayoutParams)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM