Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android布局中的绝对定心_Java_Android_Xml_Android Layout - Fatal编程技术网

Java Android布局中的绝对定心

Java Android布局中的绝对定心,java,android,xml,android-layout,Java,Android,Xml,Android Layout,我花了很多时间想弄明白这一点。我正在构建一个对话框布局,并尝试使标题相对于对话框居中,同时在标题的两侧有两个按钮。按钮应朝向最左侧和最右侧进行“重力调整” 最简单的部分是使对话框居中,或者按最左边和最右边的按钮。让他们在同一条线上友好相处 思考这个问题的简单方法: 标题在对话框中居中 两个按钮在同一条线上独立地左右对齐 有什么想法吗?在我看来,我会尝试创建一个自定义对话框,并使用TableLayout来放置元素。 这样,您可以放置按钮,并使用标题上的属性stretchcolumn来按下屏幕侧面的

我花了很多时间想弄明白这一点。我正在构建一个对话框布局,并尝试使标题相对于对话框居中,同时在标题的两侧有两个按钮。按钮应朝向最左侧和最右侧进行“重力调整”

最简单的部分是使对话框居中,或者按最左边和最右边的按钮。让他们在同一条线上友好相处

思考这个问题的简单方法:

  • 标题在对话框中居中
  • 两个按钮在同一条线上独立地左右对齐

  • 有什么想法吗?

    在我看来,我会尝试创建一个自定义对话框,并使用TableLayout来放置元素。 这样,您可以放置按钮,并使用标题上的属性stretchcolumn来按下屏幕侧面的按钮。(如果我理解你的话)

    如果使用这个xml示例,它应该可以工作,并且与屏幕大小/旋转无关:

    <?xml version="1.0" encoding="utf-8"?>
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:stretchColumns="1">
    
    <TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <Button android:text="Button01" android:id="@+id/Button01"
            android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
        <TextView android:text="This is your title" android:id="@+id/TextView01"
            android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" ></TextView>
        <Button android:text="Button02" android:id="@+id/Button02"
            android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
    </TableRow>
    </TableLayout>
    
    
    
    感谢赛菲的快速回复。如果我能保证屏幕大小,这会有用吗?比如,我不知道在未知分辨率上按下右/左按钮有多远,或者有一个我还不完全理解的属性允许这样做。谢谢。我不认为你需要知道屏幕的大小……我会为你做一些测试并编辑我的帖子。