首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使滚动视图中的线性布局填充整个区域

如何使滚动视图中的线性布局填充整个区域
EN

Stack Overflow用户
提问于 2013-02-13 01:11:50
回答 1查看 26K关注 0票数 25
代码语言:javascript
复制
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ScrollView
        android:id="@+id/scrollView1"
        android:background="#000000"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <LinearLayout
            android:id="@+id/linear1"
            android:background="#FF0000"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <LinearLayout
                android:background="#00FF00"
                android:id="@+id/linear2"
                android:layout_width="match_parent"
                android:layout_height="200dip"
                android:orientation="vertical" >
            </LinearLayout>

            <LinearLayout
                android:background="#0000FF"
                android:id="@+id/linear3"
                android:layout_width="match_parent"
                android:layout_height="100dip"
                android:orientation="vertical" >
            </LinearLayout>

        </LinearLayout>
    </ScrollView>
</RelativeLayout>

这是我的布局,我希望看到一个红色的背景(因为linear1的背景是红色的,并且具有填充父级的属性),另外两个布局在带有绿色和蓝色的linear1上

但我实际看到的是来自滚动视图的黑色背景,来自linear2和linear3的绿色和蓝色背景,但没有来自linear1的红色背景

即线性行为类似于android:layout_height="wrap_content“设置为android:layout_height="match_parent”

有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-13 01:15:02

您需要设置fillViewport:

代码语言:javascript
复制
<ScrollView
    android:id="@+id/scrollView1"
    android:background="#000000"
    android:layout_width="match_parent"
    android:fillViewport="true" <!-- here -->
    android:layout_height="match_parent" >

    ...

 </ScrollView>

information

票数 86
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14837983

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档