Кнопка регулировки под содержанием упражнения - PullRequest
0 голосов
/ 18 мая 2018

У меня возникают трудности с настройкой макета моей активности, я хочу, чтобы содержимое было внутри "scrollview", а внизу страницы была кнопка.Мой макет уже делает почти это, проблема в том, что когда контент достигает определенной точки, он попадает за кнопку, которую я хочу, и держу контент всегда над кнопкой независимо от размера.

мой макет:

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

Ответы [ 6 ]

0 голосов
/ 18 мая 2018

Вы не требуете прокрутки, поскольку у вас есть recycelerView и кнопка в LinearLayout и добавление android:orientation="vertical" в LinearLayout, как показано ниже также

  <?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>
0 голосов
/ 18 мая 2018

Сначала удалите Scrollview, потому что у recycle есть собственное свойство прокрутки, теперь для более простого изменения его на относительное расположение установите recycelerView над кнопкой, чтобы кнопка никогда не отставала, если в recycelerView есть больше, она будет содержатьвсегда будьте ниже recycelerView, посмотрите.

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

Надеюсь, это поможет вам !!

0 голосов
/ 18 мая 2018

Сделайте эти изменения ниже в макете

 <?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>
0 голосов
/ 18 мая 2018

- Замените компоновку координатора линейной компоновкой с вертикальной ориентацией и удалите представление прокрутки, потому что в recycleview есть свойство прокрутки по умолчанию, поэтому при установке веса 1 для перезаписи используйте приведенный ниже код, и вы сможете достичь желаемого.

<?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>
0 голосов
/ 18 мая 2018

Если вы хотите ScrollView , тогда можете использовать NestedScrollView вместо Scrollview

Но если в нем только один просмотрщик, я предлагаю не использовать Scrollview,поскольку Scrollview не для этой цели

Я хочу и сохраняю содержимое всегда над кнопкой независимо от размера

Для этого вы можете попробовать следующее решение:

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

in recyclerview

Для cliptopedding

0 голосов
/ 18 мая 2018

Удалить RecyclerView из ScrollView не нужно использовать ScrollView

FYI

RecyclerView имеет свое собственное поведение прокрутки и ваш ScrollViewимеет одного ребенка RecyclerView, так что я думаю, что бессмысленно использовать RecyclerView внутри ScrollView

он попадает за кнопку, которую я хочу, и держу содержимое всегда над кнопкой независимо от того,размер.

Кроме того, попробуйте добавить bottom-padding или bottom-margin к вашему RecyclerView, чтобы показать нижний контент в конце экрана

SAMPLEКОД

<?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>
...