简体   繁体   中英

Show Button in LinearLayout always on Bottom of the screen while Scrolling

I have a LinearLayout with a few Elements which is in a ScrollView. Now i want to have a Button on Bottom of the Screen (not on Bottom of the ScrollView), which is always shown in front, also while Scrolling the rest of the content of this Layout. How can i achieve this?

This is my 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>

And thats the part in the Code where I add my current Button (which is always shown on bottom of the ScrollView):

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

I appreciate any help.

if you can add button to xml like this it's possible and you can make the button visible and invisible when you wish inside your activity class.

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM