0

I have a layout that looks like this,

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

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <include
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                layout="@layout/layout1" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"/>

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="button"/>
        </LinearLayout>
    </ScrollView>
</LinearLayout>

I want the button to appear at the bottom of the screen which works fine if use it with an activity.When i try to use it with a fragment though (inside a FrameLayout) the button doesn't show at all.Any suggestions?

EDIT

Thanks for your answers but i've already tried all that.Let me clarify something.I have a main layout that contains a Toolbar and a Framelayout.This FrameLayout is used for my 4-5 app's Fragments.One of them has that previous layout i posted.

tasgr86
  • 299
  • 2
  • 7
  • 17
  • 1
    try using relativelayout. and then set the property to align_ParentBottom = true. It will show at the bottom no matter what – Umair Nov 21 '16 at 10:20
  • go through this http://stackoverflow.com/questions/3482742/gravity-and-layout-gravity-on-android/40080065#40080065 – sushildlh Nov 21 '16 at 10:21
  • Hi @ tasgr86 it's compulsary to use FrameLayout..? – Dileep Patel Nov 21 '16 at 10:30
  • @ Dillep Preferably yes, but if you have something else to suggest i'm all ears – tasgr86 Nov 21 '16 at 10:43
  • keep your xml file as it is just change your first linearlayout tag to relative layout and place a button below scrollview with a tag align_ParentBottom = true. – Akshay Shah Nov 21 '16 at 12:15

5 Answers5

1

Use layout_weight

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

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <include
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                layout="@layout/layout1" />

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1" />

        </LinearLayout>
    </ScrollView>

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

</LinearLayout>
Mahesh Babariya
  • 4,560
  • 6
  • 39
  • 54
0

try to use:

android:layout_gravity="bottom"

or:

android:layout_alignParentBottom="true"

in the botton tag.

Alessandro Argentieri
  • 2,901
  • 3
  • 32
  • 62
0

You need set property for ScrollView

android:fillViewport="true"

and the add below line to your button

android:layout_alignParentBottom="true"
android:layout_gravity="center_horizontal"

I have Edited your code just try this

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

<ScrollView
    android:layout_width="match_parent"
    android:fillViewport="true"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:orientation="vertical"
        android:layout_height="match_parent">

        <include
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            layout="@layout/layout1" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"/>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:text="button"
            android:layout_gravity="center_horizontal" />

    </LinearLayout>
</ScrollView>

Anil
  • 1,605
  • 1
  • 14
  • 24
0

You should use ScrollView as a root layout than LinearLayout here.

And try this property inside scrollview :

android:fillViewport="true"

May be it will help you.

Vishal Chhodwani
  • 2,567
  • 5
  • 27
  • 40
0

tasgr86 try to this code hope this can do some idea or help..

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/button">

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

        <include
            layout="@layout/layout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Test" />

    </LinearLayout>
</ScrollView>

<Button
    android:id="@+id/button"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="5dp"
    android:text="button" />

</RelativeLayout>
Dileep Patel
  • 1,988
  • 2
  • 12
  • 26