0

我有一个看起来像这样的活动:

活动界面

当我在模拟器上运行应用程序时,图钉不在便利贴上方,所以我知道不同尺寸的屏幕会有问题。便利贴和软木板是背景。我怎样才能做到这一点,以便在任何尺寸的屏幕上,图钉都将位于正确的位置?它目前是线性布局。

4

2 回答 2

1

最适合您的解决方案是使用 RelativeLayout。我建议您的便利贴不要成为背景的一部分,而是自己的 ImageView,以便您可以随时重新调整大小以适应任何屏幕。因此,您可以将其添加到您的软木塞代码中。

<ImageView
android:id="@+id/cork"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignTop="@+id/postit_note"
/>

它将软木塞居中,并将其与便利贴的顶部对齐。

您可以在此处查看所有其他属性以帮助您使用 RelativeLayouts

于 2013-10-18T17:52:27.480 回答
0

根据上述建议,执行以下操作:

<RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">

        <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageView"
                android:layout_alignParentTop="true"
                android:src="@drawable/postit"/>

        <ImageButton
                android:id="@+id/angry_btn"
                android:background="@drawable/pushpin"
                android:layout_width="80dp"
                android:layout_height="80dp"
                android:shadowDx="0"
                android:shadowDy="0"
                android:layout_gravity="center"
                android:shadowRadius="5"
                android:layout_centerHorizontal="true"
                android:layout_alignParentTop="true"/>

    </RelativeLayout>

注意:您应该将棕色部分作为最外层布局的背景,并为便利贴设置一个单独的图像,您应该将其设置为我上面显示的图像视图。

于 2013-10-18T18:01:18.357 回答