-2

This is my problem.

I have a RelativeLayout including a ScrollView and a LinearLayout (with OK/Cancel buttons)

I'm using this as Dialog and I want that OK/Cancel Buttons works as a "footer" but not filling all screen size if not needed (So i don't wannt to use the AlignParentBottom parameter), but when scrollview is way too long, my LinearLayout gets "hide"

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout0"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <ScrollView
        android:id="@+id/ScrollView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:scrollbarSize="12dip" >

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="6dp"
            android:layout_marginTop="6dp"
            android:orientation="vertical"
            android:paddingLeft="8dip"
            android:paddingRight="8dip" >

            <LinearLayout
                android:id="@+id/ly_sel_4_5"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:orientation="vertical"
                android:paddingBottom="16dip"
                android:paddingTop="8dp" >

                <LinearLayout
                    android:id="@+id/p2"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical" >

                    <TextView
                        android:id="@+id/p_label_cvv"
                        style="@style/SpecialText"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="CVV  " />

                    <EditText
                        android:id="@+id/p_cvv"
                        android:layout_width="100dp"
                        android:layout_height="wrap_content"
                        android:layout_below="@id/p_label_cvv"
                        android:background="@android:drawable/editbox_background"
                        android:inputType="numberPassword"
                        android:maxLength="8" >
                        <requestFocus />
                     </EditText>
                </LinearLayout>

            <LinearLayout
                android:id="@+id/p3"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/p2"
                android:orientation="vertical" >

                <TextView
                    android:id="@+id/label_sellerPIN"
                    style="@style/SpecialText"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="PIN del vendedor " />

                <EditText
                    android:id="@+id/sellerPIN"
                    android:layout_width="100dp"
                    android:layout_height="wrap_content"
                    android:background="@android:drawable/editbox_background"
                    android:inputType="numberPassword"
                    android:maxLength="4"
                    android:nextFocusDown="@+id/continuar4" />
                </LinearLayout>

            </LinearLayout>
        </RelativeLayout>
    </ScrollView>

    <LinearLayout
        android:id="@+id/LinearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/ScrollView1"
        android:layout_marginTop="18dp"
        android:background="@color/light_grey"
        android:gravity="center" >

        <Button
            android:id="@+id/continuar4"
            android:background="@drawable/custom_button_grey"
            style="@style/SpecialTextButtonDialog"
            android:layout_marginTop="1dp"
            android:layout_marginRight="1dp"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:minHeight="56dp"
            android:minWidth="120dp"
            android:text="@string/continuar" />

        <Button
            android:id="@+id/cancelar4"
            android:background="@drawable/custom_button_grey"
            style="@style/SpecialTextButtonDialog"
            android:layout_marginTop="1dp"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:minHeight="56dp"
            android:minWidth="120dp"
            android:text="@string/cancelar" />

    </LinearLayout>
</LinearLayout>

What I want to want is that if the content in ScrollView becomes too big to appear... it won't displace my LinearLayout as if buttons were inside de ScrollView, but they get stuck at the bottom of de Dialog.

Thanks all.

Jalper
  • 1
  • 2

1 Answers1

0

Try this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"

     ... ...
>

    <ScrollView
        ... ...
        android:layout_above="@+id/btGroup"
        android:layout_marginBottom="8dp"
        android:layout_alignParentTop="true"
    >

     //other views
     ... ...

    </ScrollView>

    <RelativeLayout
        android:id="@+id/btGroup"
        ... ...
        android:layout_alignParentBottom="true"
    >

        <Button
            android:id="@+id/btOk"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"  
            android:layout_alignParentLeft="true"
        />
        <Button
            android:id="@+id/btCancel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"  
            android:layout_alignParentRight="true"
        />

    </RelativeLayout>

 </RelativeLayout>

Hope this help!

Xcihnegn
  • 11,579
  • 10
  • 33
  • 33
  • If Scrollview is too long to fit on screen and I scrolldown to see its content I can reach the end of the ScrollView, but Buttons Layout are still unreachable an hidden. – Jalper Mar 26 '15 at 17:36
  • no, buttons are aligned to the screen bottom, not scrolling with `ScrollView` – Xcihnegn Mar 26 '15 at 18:04
  • @Xcihnegn Nice solution. Is there a way to achieve using a LinearLayout rather than using the layout_alignParentBottom and RelativeLayout? – AJW Nov 11 '18 at 01:26