CheckBox 没有停留在对话框的底部

CheckBox not staying at bottom of dialog

在我的自定义对话框中,我试图让我的复选框保留在我的滚动视图下方,但它不起作用。我尝试在 xml 中的滚动视图下添加复选框,但每当我 运行 应用程序时它都不会出现。需要做什么才能使复选框保留在对话框的底部(在滚动视图下方),并且在滚动时不成为滚动视图的一部分?我根本不希望我的复选框随滚动视图一起滚动。

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>

尝试在新 LinearLayout 中设置 checkboxScrolView 并将 checkbox 放在 ScrollView 之外,如下所示:

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

更新

如何扩充 xml 文件并将其设置为 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();

为您的布局文件试试这个。这是您的 xml 文件,经过一些修改。

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