非拉伸ScrollView

时间:2011-03-03 10:12:46

标签: android scrollview

我在衬里布局中有一个滚动视图,这是我的布局文件

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <!-- Other widgets go here -->
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <!-- Scroll view content -->
    </ScrollView>
</LinearLayout>

我希望ScrolView的高度取决于其内容 - 包装它,但是如果此高度使整个布局高度超过屏幕大小,则应将其固定以适应屏幕的高度。 如何实现呢?

2 个答案:

答案 0 :(得分:6)

如果您希望滚动视图填满整个屏幕,即使数据不够,请尝试使用

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <!-- Other widgets go here -->
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true">
        <!-- Scroll view content -->
    </ScrollView>
</LinearLayout>

答案 1 :(得分:-1)

将此属性添加到scrollview

android:fillViewport="true"