【发布时间】:2015-11-29 04:55:05
【问题描述】:
我知道布局在不同的屏幕尺寸上看起来会有所不同,但我在制作此布局时并没有考虑到这一点。所以,它是为正常屏幕尺寸设计的,默认情况下,我的手机屏幕也是正常的。
问题是,布局看起来与应有的不同。这是我手机上的样子,请注意四个图像按钮稍微偏右
这就是它应该是什么样子,如android studios布局工具所示。 注意,它很好地居中,应该是这样的:
这是我的 xml 代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.ruchir.circleswithmap.MainActivity"
android:id="@+id/layout">
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/Blue"
android:layout_marginTop="108dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="73dp"
android:layout_marginStart="73dp"
android:background="@drawable/bluecircle" />
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/Green"
android:layout_below="@+id/Blue"
android:layout_alignLeft="@+id/Blue"
android:layout_alignStart="@+id/Blue"
android:background="@drawable/greencircle" />
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/Red"
android:layout_alignTop="@+id/Blue"
android:layout_toRightOf="@+id/Blue"
android:layout_toEndOf="@+id/Blue"
android:background="@drawable/redcircle" />
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="@+id/Purple"
android:layout_alignBottom="@+id/Green"
android:layout_alignLeft="@+id/Red"
android:layout_alignStart="@+id/Red"
android:background="@drawable/purplesquare" />
</RelativeLayout>
这是为什么?我该如何解决它,以便我手机上的布局也居中,因为它应该是?非常感谢您的帮助!
【问题讨论】:
-
发布你的布局的xml,否则我们帮不了你。
-
粘贴您的 xml 布局。所以我们可以提供帮助
-
@TedHopp 对不起。我已经更新了我的问题! :)
-
@FarhadFaghihi 对不起。我已经更新了我的问题! :)
标签: android arrays string android-layout android-studio