如何在Android对话框中央布局? [英] How to center layout inside of Android Dialog?

查看:169
本文介绍了如何在Android对话框中央布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个自定义对话框,并将其内容置于中心位置,但总是以左对齐方式结束。这是aboutdialog.xml:

I am trying to create a custom Dialog, and have its content centered, but it is always ending up left-aligned. Here is aboutdialog.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:a="http://schemas.android.com/apk/res/android"
  a:orientation="vertical"
  a:id="@+id/AboutDialogLayout" 
  a:layout_width="fill_parent" 
  a:layout_height="fill_parent" 
  a:layout_gravity="center_horizontal" 
  a:gravity="center_horizontal">

    <ImageView a:id="@+id/imageView1" 
               a:src="@drawable/pricebook" 
               a:layout_height="wrap_content" 
               a:layout_width="wrap_content"/>
    <TextView a:layout_height="wrap_content"         
              a:textAppearance="?android:attr/textAppearanceLarge" 
              a:id="@+id/textView1" 
              a:text="Price Book" 
              a:layout_width="wrap_content"/>
    <TextView a:layout_height="wrap_content" 
              a:id="@+id/textView2" 
              a:layout_width="wrap_content" 
              a:text="foo"/>
</LinearLayout>

我的(相关)代码:

Dialog d = new Dialog(this);
d.setContentView(R.layout.aboutdialog);
d.setTitle(R.string.app_name);

我在这里缺少什么?感谢您的帮助。

What am I missing here? Thanks for the assistance.

图片:

推荐答案

尝试编辑到: a:layout_gravity =center_horizo​​ntal | center_vertical

OR

使用Relative_Layout并将线性布局与父节点的中心对齐为 wrap_content 的fill_parent

try to edit to this: a:layout_gravity="center_horizontal|center_vertical"
OR
use Relative_Layout and align linear layout to center of parent with fill_parent for Relative wrap_content for Linear.

与我在中心

这篇关于如何在Android对话框中央布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆