gpt4 book ai didi

android - 删除对话框列表底部的空格

转载 作者:行者123 更新时间:2023-11-29 21:39:04 26 4
gpt4 key购买 nike

enter image description here

当你打开对话框窗口时,我有它,在 Eclipse 中的 DumpView 层次结构中,5 个选项下面有这个空白...它说它是 (2) FrameLayout [34,894][686,1022]。

我的代码是:

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.sync_frequency);
ListView listView = new ListView(getActivity());
String[] syncOptions = mSyncOptions;
ArrayAdapter<String> modeAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.select_dialog_singlechoice, android.R.id.text1, syncOptions);
builder.setSingleChoiceItems(modeAdapter, 0, new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
int selectedPosition = ((AlertDialog)dialog).getListView().getCheckedItemPosition();
Log.d(TAG, "Position is " + selectedPosition);

}
});
builder.setView(listView);
builder.setNegativeButton(R.string.sync_cancel,null);
final Dialog dialog = builder.create();
dialog.getWindow().setLayout(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
dialog.show();

我正在尝试摆脱那里的空白...我不确定如何摆脱它...我什至尝试过 dialog.getWindow().setLayout(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

但它并没有切断空间。我猜是因为它将它视为一个框架布局而不是空白区域。谢谢!

最佳答案

您是否尝试过将布局参数设置为 listView(在展开为对话框之前)?

ListView listView = new ListView(getActivity());
listView.setLayout(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
.
.
.
builder.setView(listView);

另一种选择是不在对话框上使用 setView,而是使用 setAdapter(),如下例所示:

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.sync_frequency);
ListView listView = new ListView(getActivity());
String[] syncOptions = mSyncOptions;
ArrayAdapter<String> modeAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.select_dialog_singlechoice, android.R.id.text1, syncOptions);
builder.setAdapter(modeAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.setNegativeButton(R.string.sync_cancel,null);
final Dialog dialog = builder.create();
dialog.show();

关于android - 删除对话框列表底部的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17599733/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com