对如下布局:
----------------------------------------
| LinearLayout |
----------------------------------------
| |
| |
| |
| ScrollView |
| |
| |
| |
| |
| |
----------------------------------------
| LinearLayout |
----------------------------------------
想达到的效果是上下各有一固定宽高的LinearLayout, 中间是一个ScrollView,ScrollView随着其中内容的多少可长可短.
这布局的特殊性是底部有一LinearLayout要始终显示出来,而不是在长长的ScrollView的后面(如果ScrollView较长的话,在第一屏就会一眼看不到底部的Linearlayout)。
如何实现呢?
其实很简单,给ScrollView加上以下属性
android:fillViewPort="true"
android:layout_weight="1"
android:fillViewport Defines whether the scrollview should stretch its content to fill the viewport.
该属性决定当其内容宽高不足以填满可以区域时,是否将ScrollView将其内容区域拉伸以至填满可见区域。
android:layout_weight="1" 而上下LinearLayout不设置android:layout_weight属性,即默认为0,这样,ScrollView即老填满占据上下LinearLayout以外的中间空间。
本文介绍如何在Android应用中实现上下各有固定宽高的LinearLayout与中间可滚动的ScrollView布局,确保底部LinearLayout始终可见,不受ScrollView内容长度影响。
4751

被折叠的 条评论
为什么被折叠?



