我有一个ScrollView中有几个Elements的LinearLayout。
现在,我想在屏幕底部(而不是在ScrollView的底部)上有一个按钮,该按钮始终显示在前面,同时滚动此Layout的其余内容。我怎样才能做到这一点?
这是我的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中,则可以,并且您可以在活动类中希望显示和隐藏按钮。
<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>