Lacoste
Lacoste

Reputation: 13

Button at the bottom of the ScrollView

I have button inside ScrollView

I have put the button inside a scrollview because sometimes contents exceed screen size, in that case I want the button to be at the end of the content but I want to the button to be on the bottom of the screen when the contents do not exceed screen size

This is my code

<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"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.asmgx.test21.app.MainActivity">

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/vsvContents"
        android:fillViewport="true"
        android:layout_alignParentBottom="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        >
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:fillViewport="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:orientation="vertical">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/tv1"
            android:layout_alignParentTop="true"
            android:layout_alignParentStart="true"
            android:text="Hello..." />
        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Button"
            android:id="@+id/btnDetOrg"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:layout_centerHorizontal="true"
            />
        </LinearLayout>
    </ScrollView>

</RelativeLayout>

Upvotes: 0

Views: 695

Answers (1)

Aman Systematix
Aman Systematix

Reputation: 347

Add blank view just before button and set its weight 1.

    <View
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

hope this will solve your issue.

Upvotes: 3

Related Questions