gpt4 book ai didi

Android 底部粘滞按钮在滚动时向上向下移动

转载 作者:太空狗 更新时间:2023-10-29 16:31:16 26 4
gpt4 key购买 nike

我有一个选项卡式布局,我想在底部有一个粘性按钮。当布局大于屏幕大小时,我可以向上滚动,工具栏也会向上滚动以将选项卡对齐为最顶部的元素。当我滚动时,Button 也会向上滚动,因为我在底部有一个填充以在它启动时保持它的状态。

Before Scroll After Scroll (Button moves up)

activity_main.xml

<?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:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="io.sampleapp.MainActivity">

<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/appbar_padding_top"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay">

</android.support.v7.widget.Toolbar>

<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

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

<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />



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

fragment_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="io.sampleapp.MainActivity$PlaceholderFragment">

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

<Button
android:id="@+id/bottomButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="54dp"
android:background="#555555"
android:text="dummy"
android:textColor="#ffffff" />

</RelativeLayout>

最佳答案

我认为 Button 应该在 CoordinatorLayout 标签之外,尝试从 fragment_main.xml 中删除 Button 并将其添加到 activity_main.xml喜欢:

<android.support.v4.view.ViewPager

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

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

<Button
android:id="@+id/bottomButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="54dp"
android:background="#555555"
android:text="dummy"
android:textColor="#ffffff" />

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

在其他 fragment 中,如果您不需要该按钮,您可以将其设置为不可见。

关于Android 底部粘滞按钮在滚动时向上向下移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38026916/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com