android - 滚动时始终在屏幕底部显示 LinearLayout 中的按钮

标签 android android-layout scrollview

我有一个带有几个元素的 LinearLayout,它位于 ScrollView 中。 现在我想在屏幕底部(而不是 ScrollView 底部)有一个按钮,它总是显示在前面,同时滚动此布局的其余内容。我怎样才能做到这一点?

这是我的 ScrollView :

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true"
    android:background="#e2e2e2">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/bgnLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <include
            layout="@layout/trElement"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="16dp" />

        <LinearLayout
            android:id="@+id/stopslayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_margin="16dp"
            android:showDividers="middle"
            android:divider="@drawable/divider">

        </LinearLayout>


    </LinearLayout>

</ScrollView>

这就是代码中我添加当前按钮的部分(它始终显示在 ScrollView 的底部):

Button mpbtn = ButtonFactory.makeButton(m, R.string.openMap, R.color.AndroidBlue);
LinearLayout bgnLayout = (LinearLayout) rootView.findViewById(R.id.bgnLayout);
bgnLayout.addView(mpbtn);

感谢任何帮助。

最佳答案

如果您可以像这样将按钮添加到 xml 中,这是可能的,并且您可以根据需要在 Activity 类中使按钮可见和不可见。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/parentLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
          >
    <ScrollView 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true"
        android:background="#e2e2e2">
    /////



    </ScrollView>

    <Button
     android:layout_width="wrap_content"
        android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
    />
    </RelativeLayout>

关于android - 滚动时始终在屏幕底部显示 LinearLayout 中的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29386245/

相关文章:

android - 如何在按下后以编程方式关闭 SearchView?

android - 动态改变背景LinearLayout

android - 无法在 ScrollView 中拖动搜索栏

android - 无法使子布局在 ScrollView 中填充其父布局

android - 如何从广播接收器获取应用程序上下文?

java - 在 VideoView 上叠加图像(在 Canvas 上)?

android - 将 ActionBar 添加到 Android Studio 中的默认 Google map Activity 模板

android - 在单选按钮的中心显示自定义绘图和文本

安卓发送邮件

android - 如何仅在 Scrollview/Recyclerview 的底部添加淡入淡出边缘?