Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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
Android 需要帮助编辑相对布局吗_Android_Android Relativelayout - Fatal编程技术网

Android 需要帮助编辑相对布局吗

Android 需要帮助编辑相对布局吗,android,android-relativelayout,Android,Android Relativelayout,我是android studio的新手,正在构建一个小型计算器。以下是一个屏幕截图: 正如你所看到的,它与左边框对齐,而不是我想要的中间。 所有按钮都基于√ 按钮这是件坏事吗?我如何使它们居中 谢谢 编辑-以下是我的内容代码: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ap

我是android studio的新手,正在构建一个小型计算器。以下是一个屏幕截图:

正如你所看到的,它与左边框对齐,而不是我想要的中间。 所有按钮都基于√ 按钮这是件坏事吗?我如何使它们居中

谢谢

编辑-以下是我的内容代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.thegreat.douglas.calculator.OnlyActivity"
    tools:showIn="@layout/activity_only">


    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/sqrt_key"
        android:id="@+id/sqrt_key"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="178dp"
        android:onClick="operator" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/seven_key"
        android:id="@+id/seven_key"
        android:layout_below="@+id/sqrt_key"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:onClick="numbers" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/four_key"
        android:id="@+id/four_key"
        android:layout_below="@+id/seven_key"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:onClick="numbers" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/one_key"
        android:id="@+id/one_key"
        android:layout_below="@+id/four_key"
        android:layout_alignRight="@+id/four_key"
        android:layout_alignEnd="@+id/four_key"
        android:onClick="numbers" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/zero_key"
        android:id="@+id/zero_key"
        android:layout_below="@+id/one_key"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:onClick="numbers" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/point_key"
        android:id="@+id/point_key"
        android:layout_below="@+id/one_key"
        android:layout_toRightOf="@+id/one_key"
        android:layout_toEndOf="@+id/one_key"
        android:onClick="operator" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/two_key"
        android:id="@+id/two_key"
        android:layout_above="@+id/zero_key"
        android:layout_toRightOf="@+id/one_key"
        android:layout_toEndOf="@+id/one_key"
        android:onClick="numbers" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/five_key"
        android:id="@+id/five_key"
        android:layout_above="@+id/one_key"
        android:layout_toRightOf="@+id/four_key"
        android:layout_toEndOf="@+id/four_key"
        android:onClick="numbers" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/eight_key"
        android:id="@+id/eight_key"
        android:layout_above="@+id/four_key"
        android:layout_toRightOf="@+id/seven_key"
        android:layout_toEndOf="@+id/seven_key"
        android:onClick="numbers" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/left_parenth_key"
        android:id="@+id/left_parenth_key"
        android:layout_above="@+id/seven_key"
        android:layout_toRightOf="@+id/sqrt_key"
        android:layout_toEndOf="@+id/sqrt_key"
        android:onClick="operator" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/right_parenth_key"
        android:id="@+id/right_parenth_key"
        android:layout_above="@+id/eight_key"
        android:layout_toRightOf="@+id/eight_key"
        android:layout_toEndOf="@+id/eight_key"
        android:onClick="operator" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/nine_key"
        android:id="@+id/nine_key"
        android:layout_below="@+id/left_parenth_key"
        android:layout_toRightOf="@+id/eight_key"
        android:layout_toEndOf="@+id/eight_key"
        android:onClick="numbers" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/six_key"
        android:id="@+id/six_key"
        android:layout_below="@+id/eight_key"
        android:layout_toRightOf="@+id/five_key"
        android:layout_toEndOf="@+id/five_key"
        android:onClick="numbers" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/three_key"
        android:id="@+id/three_key"
        android:layout_above="@+id/point_key"
        android:layout_toRightOf="@+id/point_key"
        android:layout_toEndOf="@+id/point_key"
        android:onClick="numbers" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/negative_key"
        android:id="@+id/negative_key"
        android:layout_alignBottom="@+id/point_key"
        android:layout_toRightOf="@+id/point_key"
        android:layout_toEndOf="@+id/point_key"
        android:onClick="specialOperator" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/multiply_key"
        android:id="@+id/multiply_key"
        android:layout_above="@+id/nine_key"
        android:layout_toRightOf="@+id/right_parenth_key"
        android:layout_toEndOf="@+id/right_parenth_key"
        android:onClick="operator" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/subtract_key"
        android:id="@+id/subtract_key"
        android:layout_above="@+id/six_key"
        android:layout_toRightOf="@+id/nine_key"
        android:layout_toEndOf="@+id/nine_key"
        android:onClick="operator" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/add_key"
        android:id="@+id/add_key"
        android:layout_above="@+id/three_key"
        android:layout_toRightOf="@+id/six_key"
        android:layout_toEndOf="@+id/six_key"
        android:onClick="operator" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/enter_key"
        android:id="@+id/enter_key"
        android:layout_toRightOf="@+id/three_key"
        android:layout_toEndOf="@+id/three_key"
        android:layout_alignBottom="@+id/negative_key"
        android:layout_alignTop="@+id/three_key"
        android:onClick="enterKey" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/clear_key"
        android:id="@+id/clear_key"
        android:onClick="clearEquation"
        android:layout_above="@+id/left_parenth_key"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text=""
        android:id="@+id/equation"
        android:layout_above="@+id/clear_key"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignRight="@+id/multiply_key"
        android:layout_alignEnd="@+id/multiply_key"
        android:clickable="false"
        android:textAlignment="textEnd"
        android:height="@dimen/abc_action_bar_stacked_max_height" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/square_key"
        android:id="@+id/square_key"
        android:layout_below="@+id/equation"
        android:layout_toRightOf="@+id/sqrt_key"
        android:layout_toEndOf="@+id/sqrt_key"
        android:onClick="specialOperator" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/negative_exp_key"
        android:id="@+id/neg_exp_key"
        android:layout_below="@+id/equation"
        android:layout_toRightOf="@+id/left_parenth_key"
        android:layout_toEndOf="@+id/left_parenth_key"
        android:onClick="specialOperator" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/divide_key"
        android:id="@+id/divide_key"
        android:layout_below="@+id/equation"
        android:layout_toRightOf="@+id/right_parenth_key"
        android:layout_toEndOf="@+id/right_parenth_key"
        android:onClick="operator" />


</RelativeLayout>

您能否共享xml布局设计代码,我们可以帮助您:
**编辑:**
在xml文件的根节点中使用`android:gravity=“center”`代码。
**就你而言:**

使用android:layout\u gravity=“center”。并在父布局的dimen文件夹中通过填充来管理空间。 你的要求应该得到满足

Can you Share the xml-layout design code than we can help you:

**Edited:**
 Use `android:gravity="center"` code in Root node of the xml file.

**In your case:**

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.thegreat.douglas.calculator.OnlyActivity"
    tools:showIn="@layout/activity_only">
<Button ...
// Add all button design code here

</RelativeLayout>