KaeL
KaeL

Reputation: 3659

Dialog: Overflowing ScrollView Content

Newbie android developer here. I have this layout for my dialog:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/llParent"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ScrollView
        android:id="@+id/svChild"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    ... content goes here

    </ScrollView>

    <Button
        android:id="@+id/btnCancel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@id/svChild"
        android:text="CANCEL"/>

    <Button
        android:id="@+id/btnOk"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@id/svChild"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:text="OK" />

</RelativeLayout>

When the ScrollView's content overflows the screen, it covers the buttons below. Sometimes the buttons are already outside the screen when changing some properties of the layout.

What I want:

Thanks

Upvotes: 0

Views: 726

Answers (1)

Yogesh Nikam
Yogesh Nikam

Reputation: 633

Use following code which will work properly

<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"
tools:context="com.demo.example.activity.ScrollDemo">


<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/btnButton"
    android:id="@+id/scrollView">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        //Place your content here

    </LinearLayout>
</ScrollView>



<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Button"
    android:id="@+id/btnButton"
    android:layout_alignParentBottom="true" />

</RelativeLayout>

Dependencies are most important here.

if you have any issue feel free to comment.

Upvotes: 1

Related Questions