我有一张带有背景图片的RelativeLayout
。在其中,我有另一个RelativeLayout
背景色。我希望第二个RelativeLayout
位于第一个<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0099cc">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp">
<RelativeLayout
android:id="@+id/cellphone"
android:layout_marginLeft="80dp"
android:layout_marginBottom="120dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:background="@drawable/cellphone">
<RelativeLayout
android:id="@+id/cellphone_screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="40dp"
android:layout_marginBottom="40dp"
android:background="#e34579">
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
的中间,但根据屏幕大小,它会出错。
以下是代码:
{{1}}
大屏幕设备的屏幕截图:
相同代码的屏幕截图,但屏幕设备的屏幕截图:
如您所见,黄色边框不应该是可见的。
我该如何解决?
P.S。:我有各种尺寸的背景图片(cellphone.png)(从drawable-ldpi到drawable-xxxhdpi)。
编辑:
xxhdpi中的 cellphone.png 图片:
答案 0 :(得分:0)
您需要使用dimens.xml
根据设备管理边距<RelativeLayout
android:id="@+id/cellphone_screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/marginLeft"
android:layout_marginRight="@dimen/marginRight"
android:layout_marginTop="@dimen/marginTop"
android:layout_marginBottom="@dimen/marginBottom"
android:background="#e34579">
</RelativeLayout>
答案 1 :(得分:0)
尝试从主RalativeLayout中删除边距
android:layout_marginLeft="@dimen/marginLeft"
android:layout_marginRight="@dimen/marginRight"
android:layout_marginTop="@dimen/marginTop"
android:layout_marginBottom="@dimen/marginBottom"