activity 内容下方的调整按钮
Adjust button below the activity contents
我在调整 activity 的布局时遇到困难,我想要的是将内容放在 "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>
从ScrollView
中删除RecyclerView
不需要使用ScrollView
仅供参考
RecyclerView
有自己的滚动行为,而你的 ScrollView
只有一个 child 是 RecyclerView
所以我认为在 RecyclerView
中使用它没有意义 ScrollView
it gets behind the button, which I want and keep the content always above the button regardless of the size.
另外,尝试向您的 RecyclerView
添加一些 bottom-padding
或 bottom-margin
以在屏幕末尾显示您的底部内容
示例代码
<?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>
如果你想要 ScrollView then can use NestedScrollView 而不是 Scrollview
但是如果里面只有一个recyclerview那么我建议不要使用Scrollview
。因为 Scrollview
不是为了这个目的
I want and keep the content always above the button regardless of the
size
为此,您可以尝试以下解决方案:
android:paddingBottom="50dp"
android:clipToPadding="false"
在recyclerview
对于
-做一件事用垂直方向的线性布局替换协调器布局并删除滚动视图,因为 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>
在布局中进行以下更改
<?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>
首先删除 Scrollview
因为回收有自己的滚动 属性,现在为了更容易我将其更改为相对布局,在按钮上方设置 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 >
希望对您有所帮助!!
您不需要滚动视图,因为您在 LinearLayout
中有 recycelerView
和按钮,并在 LinearLayout
中添加 android:orientation="vertical"
,如下所示
<?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>
我在调整 activity 的布局时遇到困难,我想要的是将内容放在 "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>
从ScrollView
中删除RecyclerView
不需要使用ScrollView
仅供参考
RecyclerView
有自己的滚动行为,而你的 ScrollView
只有一个 child 是 RecyclerView
所以我认为在 RecyclerView
中使用它没有意义 ScrollView
it gets behind the button, which I want and keep the content always above the button regardless of the size.
另外,尝试向您的 RecyclerView
添加一些 bottom-padding
或 bottom-margin
以在屏幕末尾显示您的底部内容
示例代码
<?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>
如果你想要 ScrollView then can use NestedScrollView 而不是 Scrollview
但是如果里面只有一个recyclerview那么我建议不要使用Scrollview
。因为 Scrollview
不是为了这个目的
I want and keep the content always above the button regardless of the size
为此,您可以尝试以下解决方案:
android:paddingBottom="50dp"
android:clipToPadding="false"
在recyclerview
对于
-做一件事用垂直方向的线性布局替换协调器布局并删除滚动视图,因为 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>
在布局中进行以下更改
<?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>
首先删除 Scrollview
因为回收有自己的滚动 属性,现在为了更容易我将其更改为相对布局,在按钮上方设置 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 >
希望对您有所帮助!!
您不需要滚动视图,因为您在 LinearLayout
中有 recycelerView
和按钮,并在 LinearLayout
中添加 android:orientation="vertical"
,如下所示
<?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>