如何在不同屏幕尺寸的设备中显示相同尺寸的对话框

瑞汗

我在应用程序中创建了一个固定大小的对话框。当我使用240x320像素尺寸的手机进行测试时,它显示的非常完美。但这在平板电脑中显示不正确。看下面的图片

在此处输入图片说明

手机图片

在此处输入图片说明 标签中的图片

我尝试下面的代码

public void showDialog(){
    // Create custom dialog object
    final Dialog dialog = new Dialog(MainActivity.this);
    // Include dialog.xml file
    dialog.setContentView(R.layout.dialog);
    // Set dialog title
    dialog.setTitle("Custom Dialog");

    // set values for custom dialog components - text, image and button
    TextView text = (TextView) dialog.findViewById(R.id.textDialog);
    text.setText("Custom dialog Android example.");
    ImageView image = (ImageView) dialog.findViewById(R.id.imageDialog);
    image.setImageResource(R.drawable.ic_launcher);

    dialog.show();
    dialog.getWindow().setLayout(180, 150);

    Button declineButton = (Button) dialog.findViewById(R.id.declineButton);
    // if decline button is clicked, close the custom dialog
    declineButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // Close dialog
            dialog.dismiss();
        }
    });

}

dialog.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<ImageView
    android:id="@+id/imageDialog"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginRight="6dp" />

<TextView
    android:id="@+id/textDialog"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#FFF"
    android:layout_toRightOf="@+id/imageDialog"/>

 <Button
    android:id="@+id/declineButton"
    android:layout_width="100px"
    android:layout_height="wrap_content"
    android:text=" Submit "
    android:layout_marginTop="5dp"
    android:layout_marginRight="5dp"
    android:layout_below="@+id/textDialog"
    android:layout_toRightOf="@+id/imageDialog"
    />

</RelativeLayout>

如何解决呢?

预先感谢

瑞汗

终于我找到了解决方案

我删除了以下行:dialog.setTitle(“ Custom Dialog”); dialog.getWindow()。setLayout(180,150); 行并添加了dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

更正的代码如下

public void showDialog(){
    // Create custom dialog object
    final Dialog dialog = new Dialog(MainActivity.this);
    // Include dialog.xml file
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    dialog.setContentView(R.layout.dialog);

    // set values for custom dialog components - text, image and button
    TextView text = (TextView) dialog.findViewById(R.id.textDialog);
    text.setText("Custom dialog Android example.");
    ImageView image = (ImageView) dialog.findViewById(R.id.imageDialog);
    image.setImageResource(R.drawable.ic_launcher);

    dialog.show();

    Button declineButton = (Button) dialog.findViewById(R.id.declineButton);
    // if decline button is clicked, close the custom dialog
    declineButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // Close dialog
            dialog.dismiss();
        }
    });

}

我对布局文件进行了另一处更改。已更换和线条机器人:layout_width = “FILL_PARENT”机器人:layout_height = “FILL_PARENT”机器人:layout_width = “180dp”机器人:layout_height = “150dp”

更正了以下布局

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

<ImageView
    android:id="@+id/imageDialog"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginRight="6dp" />

<TextView
    android:id="@+id/textDialog"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#FFF" />

 <Button
    android:id="@+id/declineButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text=" Submit "
    android:layout_marginTop="5dp"
    android:layout_marginRight="5dp"
    />

</LinearLayout>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在不同的屏幕尺寸下获得不同的显示

来自分类Dev

如何解决网页上的所有内容,使其在不同尺寸的屏幕上显示相同的尺寸?

来自分类Dev

Google Chrome不会在“打印”对话框中显示所有纸张尺寸

来自分类Dev

如何在本机反应中处理不同的屏幕尺寸?

来自分类Dev

如何在Android中创建不同的屏幕尺寸图像

来自分类Dev

如何在Flutter中在离开屏幕之前显示确认对话框

来自分类Dev

如何在Angular 6/8的弹出对话框屏幕中显示项目列表

来自分类Dev

如何在Android中触摸屏幕也显示进度对话框

来自分类Dev

如何在SDL中获取屏幕尺寸

来自分类Dev

如何在Android中增加屏幕尺寸

来自分类Dev

如何在android中显示位置设置对话框?

来自分类Dev

如何在HTML对话框中显示Json数据

来自分类Dev

如何在PowerShell对话框中显示HTML页面?

来自分类Dev

如何在对话框中显示片段?

来自分类Dev

如何在NetBeans的对话框中显示JTable?

来自分类Dev

如何在 ReactJS 中显示模态对话框?

来自分类Dev

如何在 Angular 的对话框中显示输入更改?

来自分类Dev

如何在所有不同的屏幕尺寸上使Image Gallery应用看起来相同?

来自分类Dev

如何在不同的屏幕尺寸上获得相同的 scrollY 高度数?

来自分类Dev

如何实现在不同屏幕尺寸相同的物理?

来自分类Dev

如何解决不同屏幕尺寸的相同dpi问题

来自分类Dev

如何在Swift中替换这些屏幕尺寸和设备类型宏?

来自分类Dev

如何在Android中以编程方式获取设备的完整屏幕尺寸?

来自分类Dev

如何限制不同屏幕尺寸的MySQL显示数据Bootsrap

来自分类Dev

如何根据Sprite Kit中的设备更改屏幕尺寸?

来自分类Dev

在Swift中,如何确定设备屏幕的物理尺寸?

来自分类Dev

创建支持不同屏幕尺寸的相同 UI?

来自分类Dev

如何根据Bootstrap 3中的屏幕尺寸以不同顺序显示div?

来自分类Dev

如何在不同的屏幕尺寸上将评论图标居中?

Related 相关文章

  1. 1

    如何在不同的屏幕尺寸下获得不同的显示

  2. 2

    如何解决网页上的所有内容,使其在不同尺寸的屏幕上显示相同的尺寸?

  3. 3

    Google Chrome不会在“打印”对话框中显示所有纸张尺寸

  4. 4

    如何在本机反应中处理不同的屏幕尺寸?

  5. 5

    如何在Android中创建不同的屏幕尺寸图像

  6. 6

    如何在Flutter中在离开屏幕之前显示确认对话框

  7. 7

    如何在Angular 6/8的弹出对话框屏幕中显示项目列表

  8. 8

    如何在Android中触摸屏幕也显示进度对话框

  9. 9

    如何在SDL中获取屏幕尺寸

  10. 10

    如何在Android中增加屏幕尺寸

  11. 11

    如何在android中显示位置设置对话框?

  12. 12

    如何在HTML对话框中显示Json数据

  13. 13

    如何在PowerShell对话框中显示HTML页面?

  14. 14

    如何在对话框中显示片段?

  15. 15

    如何在NetBeans的对话框中显示JTable?

  16. 16

    如何在 ReactJS 中显示模态对话框?

  17. 17

    如何在 Angular 的对话框中显示输入更改?

  18. 18

    如何在所有不同的屏幕尺寸上使Image Gallery应用看起来相同?

  19. 19

    如何在不同的屏幕尺寸上获得相同的 scrollY 高度数?

  20. 20

    如何实现在不同屏幕尺寸相同的物理?

  21. 21

    如何解决不同屏幕尺寸的相同dpi问题

  22. 22

    如何在Swift中替换这些屏幕尺寸和设备类型宏?

  23. 23

    如何在Android中以编程方式获取设备的完整屏幕尺寸?

  24. 24

    如何限制不同屏幕尺寸的MySQL显示数据Bootsrap

  25. 25

    如何根据Sprite Kit中的设备更改屏幕尺寸?

  26. 26

    在Swift中,如何确定设备屏幕的物理尺寸?

  27. 27

    创建支持不同屏幕尺寸的相同 UI?

  28. 28

    如何根据Bootstrap 3中的屏幕尺寸以不同顺序显示div?

  29. 29

    如何在不同的屏幕尺寸上将评论图标居中?

热门标签

归档