Android 布局中心不工作。

Android 布局中心不工作。,android,android-layout,android-linearlayout,android-relativelayout,Android,Android Layout,Android Linearlayout,Android Relativelayout,我是android新手,我正在尝试创建视图,但有一个问题我无法解决 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_ma

我是android新手,我正在尝试创建视图,但有一个问题我无法解决

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_margin="30dp">
    <LinearLayout
            android:id="@+id/layout1"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:orientation="vertical"
            android:layout_marginTop="@dimen/login_view_margin_top"
            android:layout_centerHorizontal="true"
            android:background="@drawable/rounded_white_bg">
        <EditText
                android:id="@+id/loginEditText"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:background="@drawable/dialog_edittex"
                android:layout_margin="10dp"/>
        <EditText
                android:id="@+id/passwordEditText"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginBottom="10dp"
                android:background="@drawable/dialog_edittex"/>
        <TextView
                android:id="@+id/forgetPassword"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:textColor="@android:color/black"
                android:layout_gravity="center"
                android:layout_marginBottom="10dp"
                android:textSize="@dimen/text_size_choose_order_type"/>
    </LinearLayout>
    <LinearLayout
            android:layout_below="@id/layout1"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_centerHorizontal="true"
            android:orientation="vertical">
        <Button
                android:id="@+id/loginButton"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:background="@drawable/dialog_button_bg"
                android:textColor="@color/textColor"
                android:textSize="@dimen/text_size_choose_order_type"/>
        <TextView
                android:id="@+id/register"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:textColor="@android:color/white"
                android:layout_gravity="center"
                android:layout_marginTop="15dp"
                android:textSize="@dimen/text_size_choose_order_type"/>
    </LinearLayout>

</RelativeLayout>

centerHorizontal=在android版本4.0及以上版本中工作正常,但在2.3.x中则不是。我的margin=30dp,但marginLeft在2.3.x中不工作。你能告诉我我做错了什么吗

第4版

在2.3版本中


您的
线性布局
覆盖了父级
相对长度的整个宽度。这意味着LinearLayout将覆盖水平区域,并且不会留下空间使视图水平居中

您可以尝试在
LinearLayout
android:layout\u width
上使用
wrap\u content

但是,如果您试图垂直居中视图(因为您使用了
layout\u height=“wrap\u content”
),则应改为使用
layout\u centerVertical=“true”

//尝试此方法
我有你的要求使用线性布局再次让我知道,如果有任何东西

noo dude它将在2.3.x中运行,我尝试了很多次,所以它不是问题,可能是另一个代码有问题,因为您在主相对布局中提供了匹配父项删除该匹配父项并使用填充父项选项。我不明白我在我的Nexus S和Galaxy Nexus中运行它。在银河系中,Nexus是好的,但在Nexus S中不是。家长没有帮助。我试过了你能给我们一张截图吗?顺便说一句,fill_parent和match_parent的操作完全相同,AOSP更改了标志的名称,因为他们认为它更清晰。。。
// try this 
i have your requirement using linear layout again let me know if any stuff
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center"
    android:padding="30dp">

        <EditText
            android:id="@+id/loginEditText"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"/>
        <EditText
            android:id="@+id/passwordEditText"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:inputType="textPassword"
            android:layout_marginTop="5dp"/>
        <TextView
            android:id="@+id/forgetPassword"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:textColor="@android:color/black"
            android:layout_marginTop="5dp" />

        <Button
            android:id="@+id/loginButton"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_marginTop="5dp"/>
        <TextView
            android:id="@+id/register"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:textColor="@android:color/white"
            android:layout_marginTop="5dp"/>

</LinearLayout>