我有一个选项卡式布局,我想在底部有一个粘滞按钮。 当布局大于屏幕尺寸时,我可以向上滚动,并且工具栏也会向上滚动以将选项卡对齐为最顶层元素。当我滚动时,按钮也会向上滚动,因为底部有一个填充区域,以便在启动时保持其状态。Android底部粘贴按钮在滚动上向下移动
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>
那么,什么是预期?第一个截图还是第二个? – Rajkiran
@Rajkiran当我滚动按钮不应该向上移动。它应该在底部 –
为什么你在底部填充54dp?为了补偿导航栏? – Rajkiran