gpt4 book ai didi

android - 如何使 ScrollView 中的线性布局填充整个区域

转载 作者:IT老高 更新时间:2023-10-28 22:15:50 26 4
gpt4 key购买 nike

<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 上带有绿色和蓝色背景

但我实际上看到的是 ScrollView 中的黑色背景和线性2和线性3中的绿色和蓝色,但线性1中没有红色背景

即线性表现得像 android:layout_height="wrap_content"设置不是 android:layout_height="match_parent"

有什么想法吗?

最佳答案

你需要设置fillViewport:

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

...

</ScrollView>

information

关于android - 如何使 ScrollView 中的线性布局填充整个区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14837983/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com