例如:我将为星系选项卡做一个布局(使用编辑器)。当我运行银河选项卡模拟器时,我的圈子将散布在它的“屏幕”周围。如果我为较小的手机进行布局,然后运行手机的模拟器,我会得到相同的结果——我的圈子放置在我定义的其他地方。似乎编辑器按照我想要的方式设置了我的圈子 - 相对于它们放置在上面的 imageview。但是,这些设备似乎将圆圈放置在相对于模拟设备屏幕的大小。
我尝试使用 viola_desmond_pic.getWidth() 和 viola_desmond_pic.getHeight() 以便我可以以编程方式布置圆圈,但它们只返回屏幕的大小而不是视图。我了解 dp 和不同密度的规划,但是布局编辑器/模拟器的差异很疯狂。
- 还有其他人有这个差异问题吗?我很可能会忽略一些东西。
- 如果我决定跳过 XML,如何获得 Imageview 的准确大小“viola_desmond_pic”并从特定边缘以百分比进行布局?
这是我的“layout-xlarge”文件夹中的 XML。我的目标是 Android 2.1
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout04"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/viola_desmond_pic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@string/desc"
android:scaleType="fitCenter"
android:src="@drawable/viola_desmond" />
<ImageView
android:id="@+id/keyhole"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="160dp"
android:layout_marginTop="95dp"
android:adjustViewBounds="true"
android:contentDescription="@string/desc"
android:scaleType="fitCenter"
android:src="@drawable/circle3" />
<ImageView
android:id="@+id/gun"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/keyhole"
android:layout_alignRight="@+id/cat"
android:layout_marginRight="42dp"
android:adjustViewBounds="true"
android:contentDescription="@string/desc"
android:paddingBottom="35dp"
android:paddingLeft="60dp"
android:paddingRight="50dp"
android:scaleType="fitCenter"
android:src="@drawable/circle3" />
<ImageView
android:id="@+id/popcorn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="61dp"
android:layout_marginLeft="83dp"
android:layout_toRightOf="@+id/keyhole"
android:adjustViewBounds="true"
android:contentDescription="@string/desc"
android:paddingBottom="10dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="20dp"
android:scaleType="fitCenter"
android:src="@drawable/circle3" />
<ImageView
android:id="@+id/pen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="24dp"
android:layout_marginTop="46dp"
android:adjustViewBounds="true"
android:contentDescription="@string/desc"
android:paddingBottom="140dp"
android:paddingTop="140dp"
android:src="@drawable/circle3" />
</RelativeLayout>