<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/linearLayoutQuestion"
android:layout_width="match_parent"
android:layout_height="517dp"
android:layout_above="@+id/button4"
android:layout_alignParentTop="true"
android:orientation="vertical">
ЗДЕСЬ ВЬЮХи которые добавляются динамически, во время исполнения кода
</LinearLayout>
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Button" />
</RelativeLayout>
</ScrollView>
在 LinearLayout 中添加视图时,按钮应该留在底部,如果视图很多,那么界面应该滚动,但按钮仍然在底部。如何做到这一点?如果您删除 fillViewport ,则仅保留按钮,该按钮将位于屏幕顶部。
这个 xml 在这里作为标记TabItem
<?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=".ui.LearnTickets.LearnTickets">
<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:layout_weight="1"
android:background="?attr/colorPrimary"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:title="@string/app_name">
</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.TabItem
android:id="@+id/ticket_tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1" />
<android.support.design.widget.TabItem
android:id="@+id/ticket_tabs1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2" />
</android.support.design.widget.TabLayout>
</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>

该按钮始终粘在屏幕的底部边缘并且可见,其余部分滚动: