Android 为什么不同区域的布局不同

Android 为什么不同区域的布局不同,android,layout,Android,Layout,我想问一下,如何在不同的屏幕上调整布局 当我运行应用程序时,XML中显示的布局与我的设备显示的布局不同。 尽管如此, galaxy Ace 2和三星note上的布局也不同 我可以知道为什么会这样吗?我怎样才能修复它 我希望我的布局像这样 然而,我的布局总是这样 我目前使用的是表格布局和线性布局。 我也尝试过其他布局,但没有一个符合我的需要 有人能帮我吗 绿色表示文本视图 红色代表编辑文本 <RelativeLayout xmlns:android="http://schemas.and

我想问一下,如何在不同的屏幕上调整布局

当我运行应用程序时,XML中显示的布局与我的设备显示的布局不同。 尽管如此, galaxy Ace 2和三星note上的布局也不同

我可以知道为什么会这样吗?我怎样才能修复它

我希望我的布局像这样

然而,我的布局总是这样

我目前使用的是表格布局和线性布局。 我也尝试过其他布局,但没有一个符合我的需要

有人能帮我吗

绿色表示文本视图 红色代表编辑文本

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
     android:orientation="vertical"
    android:layout_height="fill_parent"
    tools:context=".MainActivity" 
    android:background="@drawable/background">

   <TableLayout
        android:id="@+id/tableLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:stretchColumns="1" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/datetxtview"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Date:"
                android:textColor="#99FFFF"
                android:textSize="18sp"
                android:textStyle="bold" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <EditText
                android:id="@+id/date"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:clickable="false"
                android:cursorVisible="false"
                android:focusable="false"
                android:focusableInTouchMode="false"
                android:hint="DD/MM/YYYY"
                android:inputType="date"
                android:textColor="#FFFFFF"
                android:textColorHint="#0099FF"
                android:textSize="12sp" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow3"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/fuelpricetxtview"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Fuel Price ($):"
                android:textColor="#99FFFF"
                android:textSize="18sp"
                android:textStyle="bold" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow4"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <EditText
                android:id="@+id/fuelprice"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:hint="Enter the price"
                android:textColor="#FFFFFF"
                android:textColorHint="#0099FF"
                android:textSize="15sp" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow5"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/fuelpumptxtview"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Fuel Pump (litre):"
                android:textColor="#99FFFF"
                android:textSize="18sp"
                android:textStyle="bold" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow6"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <EditText
                android:id="@+id/fuelpump"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:hint="Enter the number of litres pump"
                android:textColorHint="#0099FF"
                android:textColor="#FFFFFF"
                android:textSize="15sp" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow7"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/totalcosttxtview"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Total Cost ($):"
                android:textColor="#99FFFF"
                android:textSize="18sp"
                android:textStyle="bold" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow8"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/tcost"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textColor="#FFFFFF"
                android:textSize="15sp" />
        </TableRow>




        <TableRow
            android:id="@+id/tableRow9"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/odometertxtview"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Current Odometer (mileage):"
                android:textColor="#99FFFF"
                android:textSize="18sp"
                android:textStyle="bold" 
                />
        </TableRow>




        <TableRow
            android:id="@+id/tableRow10"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <EditText
                android:id="@+id/odometer"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:ems="10"
                android:textColor="#FFFFFF"
                android:textSize="15sp" 
                 android:hint="Enter your current odometer"
                android:textColorHint="#0099FF"/>
        </TableRow>





        <TableRow
            android:id="@+id/tableRow12"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/fctxtview"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Fuel Consumption:"
                android:textColor="#99FFFF"
                android:textSize="18sp"
                android:textStyle="bold" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow13"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/fcon"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textColor="#FFFFFF"
                android:textSize="15sp" />
        </TableRow>


    </TableLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal"
        android:weightSum="90">
              <Button
                android:id="@+id/saveBTN"
                style="@style/ButtonInside"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:paddingTop="100dp"
                android:text="Save" 
                android:layout_weight="45"/>
  <Button
      android:id="@+id/cancelBTN"
      style="@style/ButtonInside"
     android:layout_width="0dp"
                  android:layout_weight="45"
      android:layout_height="wrap_content"
      android:paddingTop="100dp"
      android:text="Cancel" />

    </LinearLayout>
</RelativeLayout>

为Android设计与为iOS设备设计不同——有数千种不同的屏幕配置可用,而在iOS中,只有不到十种

<>你可以认为它与设计网站相似,反应灵敏;设计者不知道屏幕将如何寻找客户端,所以他们必须考虑大小桶,并制定一个布局,可以根据其显示的设备重新流动。 您可以在资源目录中指定限定符,其工作方式类似于网站的媒体查询(例如,
layout-sw600dp
,仅当运行它的设备的最短宽度为600个与密度无关的像素时才会使用)


请参阅。

作为用户,您可能已经注意到您的设备的屏幕和规格彼此不同(很多):

:800 x 1280(1.6纵横比)-5.3英寸,285 ppi

:480 x 800(1.6666…纵横比)-3.8英寸,246 ppi

这不是仅有的两种不同的android设备。有成千上万

您需要考虑如何使用优雅的解决方案处理所有这些问题

如果您坚持两个设备都会使组件在大小上拉伸,请将行设置为具有相等的权重。我认为您仍然可以使用TableLayout,因为它是从LinearLayout扩展而来的,但是如果您不能,您需要做更多的工作

然而,如果你这样做,较小的设备将有微小的组件,使它们都挤进小屏幕,而较大的设备(甚至平板电脑)将有巨大的UI组件

我建议你看一些关于用户界面设计和如何处理不同屏幕的谷歌IO讲座。还有许多关于它的链接,例如:


您能详细说明一下吗?你所说的差异是什么意思?我猜你没有读过,而且。如果你发布你的xml布局,看看我们如何修复它,那就太好了。另外,如果能看到你的目标的图片(或者显示要复制的工作布局的屏幕截图),也会很好。@Tobor我已经更新了它