Android Studio中预览和模拟器之间的不同布局

时间:2016-08-13 07:36:38

标签: java android android-studio layout emulation

为什么我在预览和同一部手机的模拟器中有两种不同的布局结果?我创建了一些AVD来模仿三星手机,但他们的预览和AVD并不对应..

这是我的xml文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    tools:context="ag.myapplication.MainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imageView"
            android:src="@drawable/sfondo"
            android:scaleType="fitXY"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:id="@+id/relativeLayout">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView4"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:src="@drawable/tronco1"
                android:layout_marginTop="-250dp" />

            <ImageButton
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:id="@+id/imageButton6"
                android:src="@drawable/play_h"
                android:scaleType="fitCenter"
                android:background="#00ffffff"
                android:layout_marginBottom="12dp"
                android:layout_above="@+id/imageButton7"
                android:layout_alignLeft="@+id/imageButton7"
                android:layout_alignStart="@+id/imageButton7" />

            <ImageButton
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:id="@+id/imageButton7"
                android:src="@drawable/score_h"
                android:scaleType="fitCenter"
                android:background="#00ffffff"
                android:layout_above="@+id/imageButton8"
                android:layout_alignLeft="@+id/imageButton8"
                android:layout_alignStart="@+id/imageButton8"
                android:layout_marginBottom="10dp" />

            <ImageButton
                android:layout_width="100dp"
                android:layout_height="100dp"
                android:id="@+id/imageButton8"
                android:src="@drawable/options_h"
                android:scaleType="fitCenter"
                android:background="#00ffffff"
                android:layout_above="@+id/imageButton11"
                android:layout_centerHorizontal="true"
                android:layout_marginBottom="15dp" />

            <ImageButton
                android:layout_width="170dp"
                android:layout_height="50dp"
                android:id="@+id/imageButton11"
                android:src="@drawable/removeads"
                android:scaleType="fitCenter"
                android:background="#00ffffff"
                android:layout_marginBottom="20dp"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true" />

            <ImageView
                android:layout_width="400dp"
                android:layout_height="200dp"
                android:id="@+id/imageView2"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"
                android:src="@drawable/titolo"
                android:layout_marginTop="-10dp" />

        </RelativeLayout>

    </RelativeLayout>

</LinearLayout>

只有ImageButtons的位置不同,而且imageViews应该是它们应该的位置

你能帮助我吗?

1 个答案:

答案 0 :(得分:0)

预览不如AVD可靠。您必须以模拟器显示为基础来验证您的视图是否正确显示。

最好是对应用程序的海报进行完美模拟,然后在真实设备上模拟它。

相关问题