gpt4 book ai didi

android - 需要帮助编辑相对布局

转载 作者:行者123 更新时间:2023-11-29 19:57:40 26 4
gpt4 key购买 nike

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

http://i.stack.imgur.com/Q76Oo.jpg

如您所见,它与左边框对齐,而不是居中,我希望如此。所有的按钮都是基于√按钮。这是坏事吗?如何让它们居中?

谢谢

编辑 - 这是我的 content_only 代码:

<?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>

最佳答案

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>

关于android - 需要帮助编辑相对布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36585403/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com