th3ramr0d th3ramr0d - 3 months ago 14
Android Question

Linearlayout below scrollview not showing up

The following should show a scrollview that takes up the entire screen except for a small portion large enough for a button at the bottom. When I run this the button/layout does not show up at all. Only the scrollview which takes up the entire screen with other views I have within the scrollview. Thoughts?

<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

Answer

This will do the job for you

<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>
Comments