gpt4 book ai didi

android - 无法在膨胀 View 中看到按钮

转载 作者:行者123 更新时间:2023-11-30 02:46:44 25 4
gpt4 key购买 nike

我通过扩充以下 XML 创建了 AlertDialog:

    LayoutInflater li = LayoutInflater.from(this);
View dialogView = li.inflate(R.layout.activity_list_logs, null);
ListView list = (ListView) dialogView.findViewById(R.id.listDates);

显示alertDialog的完整代码是:

private void showLogs(final List<Absentees> abs) {
LayoutInflater li = LayoutInflater.from(this);
View dialogView = li.inflate(R.layout.activity_list_logs, null);
ListView list = (ListView) dialogView.findViewById(R.id.listDates);
list.setAdapter(new CustomAdapterTagAbsentees(this,abs));
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View view,int position, long id) {
Absentees a =(Absentees)adapter.getItemAtPosition(position);
try
{
showLogDetails(a);
}
catch(Exception e)
{
show_popup(e+"");
}
}

});
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setView(dialogView);
alertDialogBuilder.setTitle("Attendance Details:");
alertDialogBuilder.setMessage("Day : ");
alertDialogBuilder
.setCancelable(true)
.setPositiveButton("Dismiss",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}

使用的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
>
<ListView
android:id="@+id/listDates"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:textSize="20sp"
/>
</LinearLayout>

关于我的问题:

如果列表足够小以适合屏幕,我可以看到“关闭”按钮(正向按钮)。 See the Normal Image

否则如果列表太大,我看不到“关闭”按钮

Please see the bottom side!!

请帮助我!!,我试图在布局本身的底部添加一个按钮,它显示正确,但我想知道为什么这种显示 positiveButton 的默认方式根本不显示

最佳答案

使用 RelativeLayout 而不是 Linear。将按钮设置为 layout_alignParentBottom="true"。将 ListView 置于 layout_above="id of button"。这将强制按钮位于屏幕底部并在绘制 ListView 之前为它们保留空间。否则 ListView 是贪婪的,会吸走所有需要的空间。

关于android - 无法在膨胀 View 中看到按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24882156/

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