开发者

How to layout scrollview and image on Android

开发者 https://www.devze.com 2023-04-07 00:49 出处:网络
I would like to have a screen where most of it is a ScrollView occupying 80% of the screen, and the lower 20% is an image. Within the ScrollView, I\'d like to be able to stack a long text over buttons

I would like to have a screen where most of it is a ScrollView occupying 80% of the screen, and the lower 20% is an image. Within the ScrollView, I'd like to be able to stack a long text over buttons at the end of it. (Think of it as a survey application.)

I am unable to get the layout to properly position the Scrollview and image. When I use wrap_content or fill_parent, the ScrollView, which contains text much longer than the screen, always pushes the image out of the screen.

How can I properly force the image to sta开发者_JS百科y on the screen and limit the ScrollView's size?


In order to get 2 or more views laid out in an arbitrarily proportional way, you must use LinearLayout's "weight" functionality. You do this be applying the layout_weight attribute to the child views in the LinearLayout. The layout_weight attribute distributes any left-over space to its children in a proportional manner, based on their relative weights.

In this case, the "left-over space" can be defined as the amount of space in the LinearLayout that would be left-over, in the absence of any layout_weight attributes on any of its children.

So, in order for the size of the views to be determined in a way that is completely proportional to the size of their parent (and thus to each other as well), you must also set their height (or width, for a horizontal LinearLayout) to 0. In this case, the left-over space is in fact the entire height (width) of the LinearLayout, which is then divvied up proportionally among the children based on their relative weights.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号