ScrollView忽略孩子的layout

ScrollView忽略孩子的layout

本文介绍了ScrollView忽略孩子的layout_height的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

获得了一个线性布局,其中包含一个文本视图和一个编辑文本. LinearLayout位于ScrollView内部.

Got a LinearLayout containing a textview and an edittext. The LinearLayout is inside a ScrollView.

ScrollView在另一个视图层次结构(工作空间布局的一部分,例如Android Homescreen kinda)内部,但这会填充父对象,包括高度和宽度(我将填充颜色设置为不同以进行检查).

The ScrollView is inside another view hierarchy (part of a Work Space layout, like the Android Homescreen kinda), but this fills parent, both height and width (I set fill color different to check this).

虽然在LinearLayout上具有layout_height和layout_width的fill_parent属性,但它仅填充父级的宽度方向,而不是高度.将高度设置为固定也不起作用/无效.实际上,就好像它卡在wrap_content上一样.

With attributes of fill_parent for layout_height and layout_width on the LinearLayout though, it's only filling the parent width-ways, not height. Setting the height to fixed also doesn't work/ no effect. It's as if it's stuck on wrap_content, in effect.

实际上,检查层次结构查看器,将其设置为match_parent.奇怪的是,LL的权重和被设置为-1(在层次结构查看器"中);权重未明确设置.

In actuality, checking the hierarchy viewer, it's set to match_parent. Oddly, the weightsum of the LL is set to -1 (in the Hierarchy Viewer); the weightsum is not explicitly set.

如果我还有其他信息可以找出为什么它不遵守layout_height属性,请告诉我:)

If there's any further info I can supply to figure out why it's not honouring the layout_height attribute, let me know :)

谢谢.

推荐答案

ScrollView具有无限的高度(或由其子项的需求确定的高度),因此layout_height="fill_parent"对于其中的视图没有意义.

ScrollView has an infinite height (or height determined by the needs of its child), so layout_height="fill_parent" is not meaningful for views inside it.

编辑-罗曼·盖伊(Romain Guy)具有关于此的有趣文章,解决方案的确是使用fillViewport.

Edit - Romain Guy has an interesting article about this, and the solution is indeed to use fillViewport.

尝试在ScrollView本身的xml中进行设置:android:fillViewport="true"

Try setting it on the ScrollView itself in xml: android:fillViewport="true"

这篇关于ScrollView忽略孩子的layout_height的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 06:33