相对布局,错误定位不同手机上的图像

时间:2013-04-06 13:50:09

标签: android drag-and-drop relativelayout drag

我正在使用相对布局开发一个拖放图像的android项目。

这里的问题是,当我在Galaxy Grand手机上测试图像时,图像按预期就位,但如果我在Galaxy Nexus上测试相同的项目,图像似乎在屏幕上错位。请查看以下屏幕截图: 1)galaxy nexus
2)星系大屏幕截图并帮我解决。

这是我的XML代码:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#3B5998" >

    <Chronometer
        android:id="@+id/chronometer"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:textSize="20sp"
        android:textStyle="bold"
        android:typeface="sans"
        android:visibility="gone" />


    <ImageView
        android:id="@+id/imagebackgroundofearth"
        android:layout_width="100dp"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:layout_height="100dp"
        android:src="@drawable/imagered" />

    <ImageView
        android:id="@+id/imageviewunderleft"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="150dp"
        android:layout_marginLeft="30dp"
        android:src="@drawable/imagered" />

    <ImageView
        android:id="@+id/imageviewunderright"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="150dp"
        android:layout_marginLeft="190dp"
        android:src="@drawable/imageorange" />

    <ImageView
        android:id="@+id/imageviewabove"
        android:layout_width="100sp"
        android:layout_height="100sp"
        android:layout_marginTop="15dp"
        android:layout_marginLeft="110dp"
        android:src="@drawable/earth" />

    <Button
        android:id="@+id/reload"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="30dp"
        android:layout_marginLeft="100dp"
        android:layout_marginRight="100dp"
        android:text="Reload" />

</RelativeLayout>

1 个答案:

答案 0 :(得分:1)

这样的一些小改动可能就是你要找的东西:

<Chronometer
        android:id="@+id/chronometer"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:textSize="20sp"
        android:textStyle="bold"
        android:typeface="sans"
        android:visibility="gone" />


<ImageView
        android:id="@+id/imagebackgroundofearth"
        android:layout_width="100dp"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:layout_height="100dp"
        android:src="@drawable/imagered" />

<ImageView
        android:id="@+id/imageviewunderleft"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="150dp"
        android:layout_marginLeft="30dp"
        android:src="@drawable/imagered" />

<ImageView
        android:id="@+id/imageviewunderright"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="150dp"
        android:layout_alignParentRight="true"
        android:layout_marginRight="30dp"
        android:src="@drawable/imageorange" />

<ImageView
        android:id="@+id/imageviewabove"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_marginTop="15dp"
        android:layout_centerHorizontal="true"
        android:src="@drawable/earth" />

<Button
        android:id="@+id/reload"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="30dp"
        android:layout_marginLeft="100dp"
        android:layout_marginRight="100dp"
        android:text="Reload" />

如果你从两个侧面测量两个底部视图,它们将始终相互匹配 - 有时更接近,有时更远一点。如果您愿意的话,也可以将它们设置为相对于中心。

我不确定你是怎么对待地球的。如果你希望它们排成一行,你最好让它们具有相同的对齐方式。另外,你在使用某些sp,我认为你的意思是dp。

我希望它适合你。