DialogFragment设置Dialog的高度

2023-12-30

我刚刚使用第一个对话框使用 DialogFragment 创建的。 一切都很好,除了我无法让对话框包装它的布局。 我的布局具有所有元素的高度wrap_content.

In MyFragmentDialog我什至找不到一种方法来暗示它可以用来设置高度FragmentDialog。我缺少什么?如何使 DialogFragment 适合其内容?

The DialogFrament's onCreateView method:

    @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Set title for this dialog
    getDialog().setTitle("Backup & Restore");
    getDialog().setCancelable(true);

    View v = inflater.inflate(R.layout.backup_restore, container, false);
    TextView msg = (TextView) v.findViewById(R.id.br_label_message);
    msg.setText("Backups are placed in the Downloads Directory:\n" + BACKUP_PATH.getAbsolutePath());
    // TextView files_label = (TextView) v.findViewById(R.id.label_restore);
    Spinner files = (Spinner) v.findViewById(R.id.br_restore_file);

    if (BACKUP_PATH.exists()) {
        FilenameFilter filter = new FilenameFilter() {
            public boolean accept(File dir, String filename) {
                File sel = new File(dir, filename);
                return filename.contains(FTYPE) || sel.isDirectory();
            }
        };
        mFileList = BACKUP_PATH.list(filter);
    } else {
        mFileList = new String[0];
    }

    ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(getActivity(), android.R.layout.simple_spinner_item, mFileList);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    files.setAdapter(adapter);
    files.setOnItemSelectedListener(this);

    Button backup = (Button) v.findViewById(R.id.br_backup_btn);
    Button restore = (Button) v.findViewById(R.id.br_restore_btn);
    Button cancel = (Button) v.findViewById(R.id.br_cancel_btn);

    backup.setOnClickListener(this);
    restore.setOnClickListener(this);
    cancel.setOnClickListener(this);

    return v;
}

这是布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="8dp" >

    <TextView
        android:id="@+id/br_label_message"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="8dp"
        android:text=""
        android:textSize="14sp" />

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TableRow
            android:id="@+id/br_tableRow1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/br_label_restore"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingRight="8dp"
                android:text="Restore file"
                android:textSize="14sp" />

            <Spinner
                android:id="@+id/br_restore_file"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </TableRow>
    </TableLayout>

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TableRow>

            <Button
                android:id="@+id/br_restore_btn"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight=".5"
                android:text="Restore"
                android:textSize="14sp" />

            <Button
                android:id="@+id/br_backup_btn"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight=".5"
                android:text="Backup"
                android:textSize="14sp" />
        </TableRow>
    </TableLayout>

    <Button
        android:id="@+id/br_cancel_btn"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Cancel"
        android:textSize="14sp" />

</LinearLayout>

Thanks,


事实证明这是一个问题LinearLayout尽管在其上设置了高度,DialogFragment它似乎占用了比我想要的更多的空间。我将布局切换为RelativeLayout内容Dialog似乎调整大小以适应内容。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

DialogFragment设置Dialog的高度 的相关文章

随机推荐

  • Box2dweb - 碰撞接触点

    我使用box2dweb 我正在尝试开发一款游戏 在某些时候 我需要找出 圆 和 盒子 之间的接触点 我所知道的是可以使用 b2ContactListener 来完成 我们可以通过使用 Post Solve Event 实现 b2Contac
  • 如何反转 dplyr::select 的辅助函数?

    如何反转辅助函数dplyr select like matches or contains 以便我可以选择不包含或不匹配特定字符串的变量 例如 假设我想选择 mtcars 数据框中没有字母 m 的所有列 我可以想象做类似的事情 mtcars
  • Java 8 DateTimeFormatter 解析可选部分

    我需要将日期时间解析为两种不同格式的字符串 19861221235959Z 1986 12 21T23 59 59Z 以下 dateTimeFormatter 模式正确解析第一种日期字符串 DateTimeFormatter ofPatte
  • MySQL 5.5:对于 innodb 中的 text/varchar 字段,以下哪一项是更好的存储方式?

    要求 Page 1 gt 显示用户及其最新 10 篇博客文章的 1 2 行预览 Page 2 gt 显示带有全文的单个博客文章 方法一 MySQL table gt userid gt varchar 50 post id gt integ
  • 基于云的 MS Access 后端选项

    我们公司使用 Access 来满足其数据库需求 它希望坚持使用当前的数据库前端 但将表迁移到某些基于云的解决方案 我们不想托管 SharePoint 或支付 Office 365 的月费 我使用 MySql 作为后端 但我们必须安装驱动程序
  • Django 中的 ModelForm 和 OneToOneField

    我在 Django 中有两个模型与OneToOneField PrinterProfile and PrinterAdress 我正在尝试制作一个表格PrinterProfileForm 但由于某种原因它没有通过PrinterAddress
  • 如何在TFS构建任务中获取代理用户能力?

    我已经宣布了userTFS 2015 构建代理中名为 MyCapability 的功能 以路径作为值 如何在构建任务的 powershell 脚本中获取此值 env MyCapability and MyCapability不工作 遗憾的是
  • Ajax 和后退按钮。哈希值发生变化,但是之前的页面状态存储在哪里?

    我试图让 ajax 与后退按钮一起工作 但缺少一些核心内容 之前的页面状态存储在哪里 CASE 1 点击 让我变红 ajax事件发生并且页面变成红色 哈希 red 点击 让我变黄 ajax事件发生并且页面变成黄色 哈希 yellow 单击后
  • 在未安装 VB6 的情况下运行 VB6 应用程序

    我的问题是 如果我想运行 VB6 应用程序 我必须在客户端计算机上安装 VB6 其实我的VB6版本 无法制作安装文件 所以我只是手动链接到exe文件 有什么方法可以让我不必安装VB6 只需复制一些文件即可运行该应用程序 Thanks 为了运
  • 模块'对象没有属性'drawMatches' opencv python

    我只是在 OpenCV 中做一个特征检测的例子 该示例如下所示 它给了我以下错误 module 对象没有属性 drawMatches 我已经检查了 OpenCV 文档 但不确定为什么会收到此错误 有谁知道为什么 import numpy a
  • 如何在nodejs的ejs文件中显示警报

    例如 我想访问文档对象并想使用警报 所以我在 ejs 文件中创建了一个函数 我想在出现错误时显示警报 所以我正在渲染我的 ejs 文件并给出 2 个参数 一个是结果 另一个是错误 并希望显示是否有错误 显示警报 res render app
  • 如何避免在 PHP 7 中的每个文件上重新声明刻度

    Overview 在 PHP 5 6 中似乎添加declare ticks 1 然后使用register tick function 将遵循任何包含并相应地提供分析信息 在 PHP 7 中 但现在看来我必须添加declare ticks 1
  • PHP短路惰性求值,php.net手册在哪里?

    抱歉 如果这听起来像是一个非常愚蠢的问题 但我用 Google 搜索了网络 还专门用 Google 搜索了 php net 网站和 stackoverflow com 网站 我知道 PHP 会短路惰性求值使用时and or 运算符 但是 P
  • Django - 连接两个模型

    对于以下模型 我想检索在历史表中具有指定间隔之间的过渡日期的条目的所有设备 class History models Model device models ForeignKey DeviceModel to field id transi
  • INNER JOIN 和锁

    我有两张桌子TableA and TableB其中有我想要同时检索和更新的信息 当我使用 SELECT TOP 2 SomeFieldA FROM TableA WITH ROWLOCK UPDLOCK READPAST 一切正常 进程 1
  • Angular 2 - 让子组件加载到父组件中(动态创建)

    我正在尝试动态创建标头 构造标头模板并将其作为 字符串 传递给我的动态组件 我的要求是在标头组件模板字符串中调用另一个组件并加载它 已经创建了一个工作Plunker https plnkr co edit ENa23Q1Qqtvi46CYn
  • MarkLogic XML 到 JSON 的转换

    我正在尝试将此 XML 文件转换为 JSON 但无法取得任何成功 我的 XML 中有两个子元素 但它只返回最后一个 如何获取 JSON 格式的两条记录 XML
  • 升级到 XCode 13(和 iOS 15)后选项卡和导航栏发生变化

    我有一个 iOS 应用程序 自从升级到 Xcode 13 以来 我注意到一些特殊的变化Tab and 导航酒吧 在 Xcode 13 中 选项卡和导航栏上现在有这个黑色区域 并且在启动应用程序时 选项卡栏和导航栏现在都是黑色的 奇怪的是 如
  • Busboy-connect 在保存文件结束之前触发(node.js,express)

    我使用 Busboy connect 从客户端获取上传数据 我尝试保存数据 然后 on finish 将状态正常返回到服务器 问题是 on finish 在文件保存结束之前触发 我是否做错了什么或者这就是模块的工作方式 服务器端代码 con
  • DialogFragment设置Dialog的高度

    我刚刚使用第一个对话框使用 DialogFragment 创建的 一切都很好 除了我无法让对话框包装它的布局 我的布局具有所有元素的高度wrap content In MyFragmentDialog我什至找不到一种方法来暗示它可以用来设置