版本2.3.3和4+之间的Android布局设计的差异

Udi*_*shi 10 android android-layout android-xml android-view

在创建简单的xml设计时,我在项目中面临一个奇怪的问题,如下所示:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:background="#FF0000"
    android:layout_marginLeft="30dp"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Button"
        android:id="@+id/button" 
        android:layout_gravity="left|center_vertical"/>
Run Code Online (Sandbox Code Playgroud)

现在看看差异,这是4.2.2中的视图:

2.3.3版本

这是2.3.3中的一个:

在此输入图像描述

如果有人可以帮助我,我将不胜感激.谢谢

Ahm*_*mad 3

如果你把它改成这样,它就可以工作:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:layout_marginLeft="30dp"
    android:background="#FF0000"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:text="New Button" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

(我想我知道为什么会这样,让我检查一下。稍后我会添加解释)