滚动视图下方的线性布局未显示

th3*_*r0d 6 android scrollview

下面应该显示一个占据整个屏幕的滚动视图,除了足够大的一小部分底部的按钮。当我运行它时,按钮/布局根本不显示。只有滚动视图与我在滚动视图中拥有的其他视图一起占据整个屏幕。想法?

<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.th3ramr0d.armybodyfatcalculator.MainActivity"
android:orientation="vertical">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    </ScrollView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button 1"
        />


    </LinearLayout>
</LinearLayout
Run Code Online (Sandbox Code Playgroud)

Tia*_*ira 5

这将为您完成工作

<RelativeLayout android:layout_width="match_parent"
     android:layout_height="match_parent"
     xmlns:android="http://schemas.android.com/apk/res/android"
     tools:context="com.th3ramr0d.armybodyfatcalculator.MainActivity"
     xmlns:tools="http://schemas.android.com/tools"
     >
     <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_above="@+id/myButton">
     </ScrollView>

     <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button 1"
        android:layout_alignParentBottom="true"
        android:id="@+id/myButton" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

  • @dex Chet 绝对是对的,但我认为主要的收获是 1) 你应该避免嵌套 RelativeLayouts 和 2) 你不应该在可以避免的情况下使用 RelativeLayout。在 OP 的情况下,RelativeLayout 是一个很好的解决方案,并且证明了它的使用是合理的,此外,它只有两个孩子,因此布局不会非常昂贵。将它包装在 LinearLayout 中肯定不会使它更快。 (2认同)