Android 安卓相对布局中心

Android 安卓相对布局中心,android,Android,在我的相对布局中,我尝试将两个数字选择器居中,第一个数字选择器居中,但第二个数字选择器仅在第一个数字选择器之后添加,它们的居中并不相等。我认为它遗漏了一些小东西,但无法使其发挥作用。下面是我的代码和用红色显示问题的图像 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_hei

在我的相对布局中,我尝试将两个数字选择器居中,第一个数字选择器居中,但第二个数字选择器仅在第一个数字选择器之后添加,它们的居中并不相等。我认为它遗漏了一些小东西,但无法使其发挥作用。下面是我的代码和用红色显示问题的图像

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:paddingLeft="16dp"
    android:paddingRight="16dp" >

    <NumberPicker
        android:id="@+id/test"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerInParent="true" />

    <NumberPicker
        android:id="@+id/test2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerInParent="true"
        android:layout_toRightOf="@+id/test" />

    <EditText
        android:id="@+id/test3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/purchaseCent"
        android:layout_centerHorizontal="true"
        android:background="@drawable/edittext_bottom_bg"
        android:hint="@string/pin"
        android:inputType="numberPassword"
        android:padding="10dp"
        android:textColorHint="#cccccc" />

    <ImageButton
        android:id="@+id/test4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/test2"
        android:background="@drawable/round_button"
        android:onClick="testMethod"
        android:src="@drawable/ic_test" />

</RelativeLayout>

尝试将两个
NumberPickers
存储到同一个对象中(即另一个
RelativeLayout
以便您可以并排放置),然后根据需要居中放置。

尝试将两个
NumberPickers
存储到同一个对象中(即另一个
RelativeLayout
以便您可以并排放置)然后以您需要的方式居中。

尝试将两个
NumberPickers
存储到同一个对象中(即另一个
RelativeLayout
,以便您可以将它们并排放置),然后以您需要的方式居中。

尝试将两个
NumberPickers
存储到同一个对象中(也就是说,另一个
相对隔片
,这样你就可以将它们并排放置)然后根据需要将其居中放置。

尝试添加一个“隔片”。
它将是1dp宽(以便完全可传输)且完全透明。
它必须有一个id,以便NumberPickers可以引用它

把这个放在中间

其他两个视图将简单地进行药剂处理,一个在其左侧,另一个在其右侧

已解决。

尝试添加“间隔垫圈”。
它将是1dp宽(以便完全可传输)且完全透明。
它必须有一个id,以便NumberPickers可以引用它

把这个放在中间

其他两个视图将简单地进行药剂处理,一个在其左侧,另一个在其右侧

已解决。

尝试添加“间隔垫圈”。
它将是1dp宽(以便完全可传输)且完全透明。
它必须有一个id,以便NumberPickers可以引用它

把这个放在中间

其他两个视图将简单地进行药剂处理,一个在其左侧,另一个在其右侧

已解决。

尝试添加“间隔垫圈”。
它将是1dp宽(以便完全可传输)且完全透明。
它必须有一个id,以便NumberPickers可以引用它

把这个放在中间

其他两个视图将简单地进行药剂处理,一个在其左侧,另一个在其右侧


已解决。

尝试这种方法,希望这能帮助您解决问题。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center">
        <NumberPicker
            android:id="@+id/test"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

        <NumberPicker
            android:id="@+id/test2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"/>
    </LinearLayout>

    <EditText
        android:id="@+id/test3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/edittext_bottom_bg"
        android:hint="@string/pin"
        android:inputType="numberPassword"
        android:padding="10dp"
        android:layout_marginTop="10dp"
        android:textColorHint="#cccccc" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="bottom|center_horizontal">
        <ImageButton
            android:id="@+id/test4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/round_button"
            android:onClick="testMethod"
            android:src="@drawable/ic_test" />
    </LinearLayout>
</LinearLayout>

试试这种方法,希望这能帮助您解决问题。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center">
        <NumberPicker
            android:id="@+id/test"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

        <NumberPicker
            android:id="@+id/test2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"/>
    </LinearLayout>

    <EditText
        android:id="@+id/test3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/edittext_bottom_bg"
        android:hint="@string/pin"
        android:inputType="numberPassword"
        android:padding="10dp"
        android:layout_marginTop="10dp"
        android:textColorHint="#cccccc" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="bottom|center_horizontal">
        <ImageButton
            android:id="@+id/test4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/round_button"
            android:onClick="testMethod"
            android:src="@drawable/ic_test" />
    </LinearLayout>
</LinearLayout>

试试这种方法,希望这能帮助您解决问题。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center">
        <NumberPicker
            android:id="@+id/test"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

        <NumberPicker
            android:id="@+id/test2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"/>
    </LinearLayout>

    <EditText
        android:id="@+id/test3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/edittext_bottom_bg"
        android:hint="@string/pin"
        android:inputType="numberPassword"
        android:padding="10dp"
        android:layout_marginTop="10dp"
        android:textColorHint="#cccccc" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="bottom|center_horizontal">
        <ImageButton
            android:id="@+id/test4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/round_button"
            android:onClick="testMethod"
            android:src="@drawable/ic_test" />
    </LinearLayout>
</LinearLayout>

试试这种方法,希望这能帮助您解决问题。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center">
        <NumberPicker
            android:id="@+id/test"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

        <NumberPicker
            android:id="@+id/test2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"/>
    </LinearLayout>

    <EditText
        android:id="@+id/test3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/edittext_bottom_bg"
        android:hint="@string/pin"
        android:inputType="numberPassword"
        android:padding="10dp"
        android:layout_marginTop="10dp"
        android:textColorHint="#cccccc" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="bottom|center_horizontal">
        <ImageButton
            android:id="@+id/test4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/round_button"
            android:onClick="testMethod"
            android:src="@drawable/ic_test" />
    </LinearLayout>
</LinearLayout>



此解决方案涉及创建
嵌套布局,这对性能不利。没错,但这只是一个示例。另一个对象可用于存储这两个
NumberPicker
s;)仍然是次优解决方案。此解决方案涉及创建
嵌套布局,这对表演不利。没错,但这只是一个例子。另一个对象可用于存储
NumberPicker
s;)仍然是次优解决方案。此解决方案涉及创建
嵌套布局
,这对性能不利。没错,但这只是一个示例。另一个对象可用于存储
NumberPicker
s;)仍然是次优解决方案。此解决方案涉及创建
嵌套布局
,这对性能不利。没错,但这只是一个示例。另一个对象可用于存储
NumberPicker
s;)还是一个次优的解决方案。完全按照你说的做,100%有效,非常感谢。好吧,毕竟经验很重要…;)照你说的做了,100%有效,万分感谢。毕竟,经验很重要……)照你说的做了,100%有效,万分感谢。毕竟,经验很重要……)照你说的做了,100%有效,万分感谢。毕竟,经验很重要……)