【发布时间】:2016-08-13 07:36:38
【问题描述】:
为什么我在同一部手机的预览和模拟器中会有两种不同的布局结果?我创建了一些 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 是它们应该在的位置
你能帮帮我吗?
【问题讨论】:
-
不,我们帮不了你……没有你的布局文件……
-
在您的布局编辑器中,从中选择要预览的设备 - 从那里选择“预览所有屏幕”。布局以这种方式显示是因为您的布局没有随着屏幕高度的变化而正确缩放。
-
有一个问题:我在avd中添加了很多三星屏幕,我也可以在预览中单独看到,但是当我选择“预览所有屏幕”时,它只显示以前的屏幕,默认的,不是我添加的。为什么?此外,在预览模式下,我检查了每台三星设备的布局,所有设备都可以。在预览模式下,我的布局在三星 Galaxy S5 中没问题,比方说,但是当我在该手机的 AVD 上运行我的应用程序时,只有我的 ImageButtons 的布局不同..这怎么可能?
-
可能取决于 API 版本(在布局编辑器中),因为添加了“ActionBar/Status Bar”...
-
在预览模式下没有操作栏但有状态栏,而在 AVD 中则没有。如何删除预览中的状态栏?无论如何,我刚刚发现在我的 layout-normal 中不会发生此问题,而在 layout-large 中会发生此问题
标签: java android android-studio layout emulation