在我的自定义对话框中,我试图让我的复选框保留在我的滚动视图下方,但它无法正常工作。我尝试在xml的scrollview下添加复选框,但每次运行应用时都不会显示。为了使复选框保留在对话框的底部(滚动视图下方),并且滚动时不能成为滚动视图的一部分,需要做些什么?我根本不希望我的复选框滚动滚动视图。
的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>
答案 0 :(得分:1)
尝试在新checkbox
内设置ScrolView
和LinearLayout
,并将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();
答案 1 :(得分:0)
尝试使用此布局文件。这是你的xml文件,有一些修改。
DECLARE @x XML='<root><Test name="checkTest">TestValue</Test></root>';
SELECT @x;
--This is the XML string in base64
DECLARE @xBase64 VARCHAR(MAX)='PHJvb3Q+DQogIDxUZXN0IG5hbWU9ImNoZWNrVGVzdCI+VGVzdFZhbHVlPC9UZXN0Pg0KPC9yb290Pg==';
CREATE TABLE #testBase64(ID INT, SomeBLOB VARBINARY(MAX));
INSERT INTO #testBase64 VALUES(1,CAST(@xBase64 AS VARBINARY(MAX)));
SELECT ID
,SomeBLOB AS TheBLOB_as_HexString
,CAST(SomeBLOB AS VARCHAR(MAX)) AS TheBLOB_back_to_Base64
--taken from here: https://stackoverflow.com/a/32231832/5089204
,CAST(CAST(CAST(CAST(SomeBLOB AS VARCHAR(MAX)) AS XML).value('.','varbinary(max)') AS VARCHAR(MAX)) AS XML) AS Back_to_XML
FROM #testBase64;
DROP TABLE #testBase64;
/*
The results
Hex-String: 0x50484A766233512B44516F67494478555A584E304947356862575539496D4E6F5A574E725647567A6443492B5647567A64465A686248566C504339555A584E305067304B504339796232393050673D3D
Base64: PHJvb3Q+DQogIDxUZXN0IG5hbWU9ImNoZWNrVGVzdCI+VGVzdFZhbHVlPC9UZXN0Pg0KPC9yb290Pg==
XML again: <root><Test name="checkTest">TestValue</Test></root>
*/