-1

In my custom dialog, I am trying to get my checkbox to stay underneath my scrollview but it's not working. I've tried adding the checkbox under the scrollview in xml but it doesn't appear whenever I run the app. What needs to be done in order for the checkbox to remain at the bottom of the dialog (underneath the scrollview), and not be part of the scrollview when I scroll that? I don't want my checkbox to scroll with the scrollview at all.

java

LayoutInflater inflater = LayoutInflater.from(this);
View dialog_layout = inflater.inflate(R.layout.fragment_overlay, (ViewGroup) findViewById(R.id.Overlay_linearLayout));
AlertDialog.Builder db = new AlertDialog.Builder(this);
db.setView(dialog_layout);
db.setPositiveButton("OK", new DialogInterface.OnClickListener() {
});
db.show();

xml

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/Overlay_linearLayout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/Overlay_scrollView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/Overlay_tableLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:weightSum="1.0">
        <TableRow
            android:padding="10dp">
            <ImageView
                android:layout_width="0px"
                android:layout_weight="0.3"
                android:layout_height="80dp"
                android:src="@drawable/img_0" />
            <TextView
                android:id="@+id/MapOverlay_textView0"
                android:layout_width="0px"
                android:layout_weight="0.7"
                android:text="@string/overlay_instruction0" />
        </TableRow>
        <TableRow
            android:padding="10dp">
            <ImageView
                android:layout_width="0px"
                android:layout_weight="0.3"
                android:layout_height="80dp"
                android:src="@drawable/img_1" />
            <TextView
                android:id="@+id/MapOverlay_textView1"
                android:layout_width="0px"
                android:layout_weight="0.7"
                android:text="@string/overlay_instruction1" />
        </TableRow>
        <TableRow
            android:padding="10dp">
            <ImageView
                android:layout_width="0px"
                android:layout_weight="0.3"
                android:layout_height="80dp"
                android:src="@drawable/img_2" />
            <TextView
                android:id="@+id/MapOverlay_textView2"
                android:layout_width="0px"
                android:layout_weight="0.7"
                android:text="@string/overlay_instruction2" />
        </TableRow>
        <TableRow
            android:padding="10dp">
            <ImageView
                android:layout_width="0px"
                android:layout_weight="0.3"
                android:layout_height="80dp"
                android:src="@drawable/img_3" />
            <TextView
                android:id="@+id/MapOverlay_textView3"
                android:layout_width="0px"
                android:layout_weight="0.7"
                android:text="@string/overlay_instruction3"
                style="@android:style/TextAppearance.Medium" />
        </TableRow>
        <TableRow>
            <CheckBox
                android:text="Don't show this again"
                android:id="@+id/skip"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </TableRow>
    </TableLayout>
</ScrollView>

wbk727
  • 8,017
  • 12
  • 61
  • 125
  • Pull the `CheckBox` out of the `ScrollView`, and put them both inside another `ViewGroup`; e.g., a vertically-oriented `LinearLayout`. – Mike M. Mar 25 '16 at 09:19
  • keep `checkbox` outside `ScrollView` and wrap both `ScrollView` and `CheckBox` in `LinearLayout` – V-rund Puro-hit Mar 25 '16 at 09:20
  • okey you can also use `RelativeLayout` and add `android:alignParentBottom="true"` to check box. EDIT : you can replace second parameter with null `View dialog_layout = inflater.inflate(R.layout.fragment_overlay, null);` – V-rund Puro-hit Mar 25 '16 at 09:30
  • 1
    Change the `ScrollView`'s `layout_height` to `0dp`, and set its `layout_weight` to `1`. – Mike M. Mar 25 '16 at 09:36
  • 1
    @MikeM. problem solved many thanks – wbk727 Mar 25 '16 at 09:53

2 Answers2

1

Try to set checkbox and ScrolView inside of new LinearLayout and put checkbox outside the ScrollView like this :

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ScrollView android:id="@+id/Overlay_scrollView"
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="1">

        <TableLayout android:id="@+id/Overlay_tableLayout"
                     xmlns:android="http://schemas.android.com/apk/res/android"
                     android:layout_width="fill_parent"
                     android:layout_height="wrap_content"
                     android:weightSum="1.0">

                <ImageView
                    android:layout_width="0px"
                    android:layout_height="80dp"
                    android:layout_weight="0.3"
                    android:src="@drawable/ic_launcher"/>

                <TextView
                    android:id="@+id/MapOverlay_textView0"
                    android:layout_width="0px"
                    android:layout_weight="0.7"
                    android:text="tion0"/>


                <ImageView
                    android:layout_width="0px"
                    android:layout_height="80dp"
                    android:layout_weight="0.3"
                    android:src="@drawable/ic_launcher"/>

                <TextView
                    android:id="@+id/MapOverlay_textView1"
                    android:layout_width="0px"
                    android:layout_weight="0.7"
                    android:text="dada"/>


                <ImageView
                    android:layout_width="0px"
                    android:layout_height="80dp"
                    android:layout_weight="0.3"
                    android:src="@drawable/ic_launcher"/>

                <TextView
                    android:id="@+id/MapOverlay_textView2"
                    android:layout_width="0px"
                    android:layout_weight="0.7"
                    android:text="ruction2"/>


                <ImageView
                    android:layout_width="0px"
                    android:layout_height="80dp"
                    android:layout_weight="0.3"
                    android:src="@drawable/ic_launcher"/>

                <TextView
                    android:id="@+id/MapOverlay_textView3"
                    style="@android:style/TextAppearance.Medium"
                    android:layout_width="0px"
                    android:layout_weight="0.7"
                    android:text="_instruction3"/>


        </TableLayout>
    </ScrollView>

    <CheckBox
        android:id="@+id/skip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Don't show this again"/>
</LinearLayout>

UPDATE

How to inflate xml file and set it to dialog

LayoutInflater inflater = getLayoutInflater();
View dialoglayout = inflater.inflate(R.layout.dialog_layout, null);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(dialoglayout);
builder.show();
Kristiyan Varbanov
  • 2,439
  • 2
  • 17
  • 37
0

Try this for your layout file. It is your xml file with some modifications.

<RelativeLayout   xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Overlay_linearLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<ScrollView
    android:id="@+id/Overlay_scrollView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/skip">

    <TableLayout
        android:id="@+id/Overlay_tableLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:weightSum="1.0">

        <TableRow android:padding="10dp">

            <ImageView
                android:layout_width="0px"
                android:layout_height="80dp"
                android:layout_weight="0.3"
                android:src="@drawable/img_0" />

            <TextView
                android:id="@+id/MapOverlay_textView0"
                android:layout_width="0px"
                android:layout_weight="0.7"
                android:text="@string/overlay_instruction0" />
        </TableRow>

        <TableRow android:padding="10dp">

            <ImageView
                android:layout_width="0px"
                android:layout_height="80dp"
                android:layout_weight="0.3"
                android:src="@drawable/img_1" />

            <TextView
                android:id="@+id/MapOverlay_textView1"
                android:layout_width="0px"
                android:layout_weight="0.7"
                android:text="@string/overlay_instruction1" />
        </TableRow>

        <TableRow android:padding="10dp">

            <ImageView
                android:layout_width="0px"
                android:layout_height="80dp"
                android:layout_weight="0.3"
                android:src="@drawable/img_2" />

            <TextView
                android:id="@+id/MapOverlay_textView2"
                android:layout_width="0px"
                android:layout_weight="0.7"
                android:text="@string/overlay_instruction2" />
        </TableRow>

        <TableRow android:padding="10dp">

            <ImageView
                android:layout_width="0px"
                android:layout_height="80dp"
                android:layout_weight="0.3"
                android:src="@drawable/img_3" />

            <TextView
                android:id="@+id/MapOverlay_textView3"
                style="@android:style/TextAppearance.Medium"
                android:layout_width="0px"
                android:layout_weight="0.7"
                android:text="@string/overlay_instruction3" />
        </TableRow>

    </TableLayout>
</ScrollView>

<CheckBox
    android:id="@+id/skip"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:text="Don't show this again" />

Akram
  • 2,158
  • 1
  • 17
  • 24