如何在scrollview中制作线性布局以填充整个区域 [英] How to make the linearlayout in scrollview to fill the whole area

查看:86
本文介绍了如何在scrollview中制作线性布局以填充整个区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<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上带有绿色和蓝色的bacgroudns

This is my layout and I expected to see a red background (because linear1 have background red and have properties to fill the parent) , and two others layout with over the linear1 with green and blue bacgroudns

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

but what I actually see is black bacground from the scrollview and green and blue from linear2 and linear3 but no red backgrund from linear1

即线性行为类似于android:layout_height ="wrap_content"设置,而不是android:layout_height ="match_parent"

namely the linear is acting like android:layout_height="wrap_content" is set not android:layout_height="match_parent"

有什么想法吗?

推荐答案

您需要设置fillViewport:

You need set fillViewport:

<ScrollView
    android:id="@+id/scrollView1"
    android:background="#000000"
    android:layout_width="match_parent"
    android:fillViewport="true" <!-- here -->
    android:layout_height="match_parent" >

    ...

 </ScrollView>

信息

这篇关于如何在scrollview中制作线性布局以填充整个区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆