-1

I'm having difficulty adjusting the layout of my activity, what I want is to have the contents inside a "scrollview", and at the bottom of the page have a button. My layout is already doing almost this, the problem that is happening is that when the content arrives to a certain point, it gets behind the button, which I want and keep the content always above the button regardless of the size.

my layout:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/fundo_degrade"
    android:fitsSystemWindows="true"
    tools:context="br.com.cifrasemusica.cifrasmusica_teoriamusical.activity.ExercicioActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar">

        <include
            android:id="@+id/Toolbar_Exercicio"
            layout="@layout/toolbar">
        </include>

    </android.support.design.widget.AppBarLayout>

    <ScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior = "@string/appbar_scrolling_view_behavior">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/RecyclerView_Exercicio"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </android.support.v7.widget.RecyclerView>

    </ScrollView>

        <Button
            android:layout_margin="5dp"
            android:id="@+id/Button_enviarExercicio"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:text="CONFIRMAR"
            android:background="@drawable/fundo_botao"
            android:layout_alignParentBottom="true" />

</android.support.design.widget.CoordinatorLayout>
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
DouglasNickson
  • 135
  • 1
  • 3
  • 15
  • 1
    Why `RecyclerView` inside `ScrollView` **FYI** `RecyclerView` has its own scrolling behavior – AskNilesh May 18 '18 at 04:36
  • You can try nesting `ScrollView` (or better `RecyclerView` directly) and Button within a `RelativeLayout` – oturan May 18 '18 at 04:48

6 Answers6

1

Remove RecyclerView from ScrollView no need to use ScrollView

FYI

RecyclerView has its own scrolling behavior and your ScrollView has inly one child is RecyclerView so i think its meaningless to use RecyclerView inside ScrollView

it gets behind the button, which I want and keep the content always above the button regardless of the size.

Also and try to add some bottom-padding or bottom-margin to your RecyclerView to show your bottom content at the end of screen

SAMPLE CODE

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/fundo_degrade"
    android:fitsSystemWindows="true"
    tools:context="br.com.cifrasemusica.cifrasmusica_teoriamusical.activity.ExercicioActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar">

        <include
            android:id="@+id/Toolbar_Exercicio"
            layout="@layout/toolbar">
        </include>

    </android.support.design.widget.AppBarLayout>


        <android.support.v7.widget.RecyclerView
            android:id="@+id/RecyclerView_Exercicio"
            android:layout_width="match_parent"
            android:paddingBottom="80dp" 
            android:clipToPadding="false" 
            android:layout_height="wrap_content">
        </android.support.v7.widget.RecyclerView>



        <Button
            android:layout_margin="5dp"
            android:id="@+id/Button_enviarExercicio"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="bottom"
            android:text="CONFIRMAR"
            android:background="@drawable/fundo_botao"
            android:layout_alignParentBottom="true" />

</android.support.design.widget.CoordinatorLayout>
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
1

If you want ScrollView then can use NestedScrollView instead of Scrollview

But if there is only one recyclerview inside that then I suggest to not use Scrollview. as Scrollview is not for this purpose

I want and keep the content always above the button regardless of the size

For this you can try below solution :

android:paddingBottom="50dp" 
android:clipToPadding="false" 

in recyclerview

For cliptopedding

Vidhi Dave
  • 5,614
  • 2
  • 33
  • 55
  • ma'am no need to use `NestedScrollView` because there no other child view inside `ScrollView` and also `RecyclerView has its own scrolling behavior` – AskNilesh May 18 '18 at 04:42
  • as you see in question there is one child in `ScrollView` and its `recyclerview` so i think ScrollView` is meaningless – AskNilesh May 18 '18 at 04:44
  • @DouglasNickson Happy to help :) let me know if any queries – Vidhi Dave May 18 '18 at 04:53
1

-Do one thing replace coordinator layout with linear layout with orientation vertical and remove scroll view because recycleview has it default scrolling property so and put weight 1 to recycle view using this below code you are able to achieve what you want.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
   xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:background="@drawable/fundo_degrade"
   android:fitsSystemWindows="true"
   android:orientation="vertical">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar">

    <include
        android:id="@+id/Toolbar_Exercicio"
        layout="@layout/toolbar">
    </include>

</android.support.design.widget.AppBarLayout>


    <android.support.v7.widget.RecyclerView
        android:id="@+id/RecyclerView_Exercicio"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <Button
        android:layout_margin="5dp"
        android:id="@+id/Button_enviarExercicio"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:text="CONFIRMAR"
        android:background="@drawable/fundo_botao"
        android:layout_alignParentBottom="true" /> 
  </LinearLayout>
Mahesh Keshvala
  • 1,349
  • 12
  • 19
1

Make these changes below in the layout

 <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/fundo_degrade"
    android:fitsSystemWindows="true"
    tools:context="br.com.cifrasemusica.cifrasmusica_teoriamusical.activity.ExercicioActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar">

        <include
            android:id="@+id/Toolbar_Exercicio"
            layout="@layout/toolbar">
        </include>

    </android.support.design.widget.AppBarLayout>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/RecyclerView_Exercicio"
            android:layout_marginBottom="50dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

        <Button
            android:layout_margin="5dp"
            android:id="@+id/Button_enviarExercicio"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:text="CONFIRMAR"
            android:background="@drawable/fundo_botao"
            android:layout_alignParentBottom="true" />

</android.support.design.widget.CoordinatorLayout>
vikas kumar
  • 10,447
  • 2
  • 46
  • 52
0

First remove Scrollview because recycle have its own scrolling property, now for more easy i change it to relative layout, set the recycelerView above the button so that button will never behind if recycelerView have more contain it will always be below of recycelerView, have look.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/fundo_degrade"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar">

        <include
            android:id="@+id/Toolbar_Exercicio"
            layout="@layout/toolbar">
        </include>

    </android.support.design.widget.AppBarLayout>


        <android.support.v7.widget.RecyclerView
            android:id="@+id/RecyclerView_Exercicio"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="id/btn">
        </android.support.v7.widget.RecyclerView>  

        <Button android:id="+id/btn"
            android:layout_margin="5dp"
            android:id="@+id/Button_enviarExercicio"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:text="CONFIRMAR"
            android:background="@drawable/fundo_botao"
            android:layout_alignParentBottom="true" />

</RelativeLayout >

Hope it will help you!!

Hemant Parmar
  • 3,924
  • 7
  • 25
  • 49
0

You dont requre scrollview as you have recycelerView and button in LinearLayout and add android:orientation="vertical" in LinearLayout as shown below also

  <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/fundo_degrade"
        android:fitsSystemWindows="true"
        tools:context="br.com.cifrasemusica.cifrasmusica_teoriamusical.activity.ExercicioActivity">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.ActionBar">

            <include
                android:id="@+id/Toolbar_Exercicio"
                layout="@layout/toolbar">
            </include>

        </android.support.design.widget.AppBarLayout>
    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            orientation="vertical">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/RecyclerView_Exercicio"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
            </android.support.v7.widget.RecyclerView>


            <Button
                android:layout_margin="5dp"
                android:id="@+id/Button_enviarExercicio"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="CONFIRMAR"
                android:background="@drawable/fundo_botao"
                 />
    </LinearLayout/>
    </android.support.design.widget.CoordinatorLayout>
Hemant Parmar
  • 3,924
  • 7
  • 25
  • 49