【发布时间】:2016-03-11 13:54:03
【问题描述】:
我正在尝试制作一个迷宫应用。只有我注意到一个问题。
整个迷宫是用 XML 设计的,仅使用 dp 作为尺寸,但在某些手机上看起来仍然很遥远。我做错了什么?
<?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="xander.woutzijnemptyactivity.MainActivity"
>
<!-- Power ups -->
<ImageView
android:layout_width="@dimen/ball_dimension"
android:layout_height="@dimen/ball_dimension"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:id="@+id/power_up_0"
android:src="@drawable/power_up_pink"
android:layout_marginTop="60dp"
android:layout_marginLeft="200dp" />
<ImageView
android:layout_width="@dimen/ball_dimension"
android:layout_height="@dimen/ball_dimension"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:id="@+id/power_up_1"
android:src="@drawable/power_up_red"
android:layout_marginTop="200dp"
android:layout_marginLeft="100dp" />
<ImageView
android:layout_width="@dimen/ball_dimension"
android:layout_height="@dimen/ball_dimension"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:id="@+id/power_up_2"
android:src="@drawable/power_up_blue"
android:layout_marginTop="150dp"
android:layout_marginLeft="200dp" />
<!-- Ball -->
<ImageView
android:layout_width="@dimen/ball_dimension"
android:layout_height="@dimen/ball_dimension"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:id="@+id/ball"
android:src="@drawable/ball_128"
android:layout_marginTop="30dp"
android:layout_marginLeft="100dp" />
<!-- Four border walls -->
<ImageView
android:layout_width="10dp"
android:layout_height="270dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:id="@+id/wall0"
android:background="#000000"
android:alpha="1"
android:layout_marginTop="0dp"
android:layout_marginLeft="75dp" />
<ImageView
android:layout_width="10dp"
android:layout_height="270dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:id="@+id/wall1"
android:background="#000000"
android:alpha="1"
android:layout_marginTop="0dp"
android:layout_marginLeft="566dp" />
<ImageView
android:layout_width="500dp"
android:layout_height="10dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:id="@+id/wall2"
android:background="#000000"
android:alpha="1"
android:layout_marginTop="260dp"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="500dp"
android:layout_height="10dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:id="@+id/wall3"
android:background="#000000"
android:alpha="1"
android:layout_marginTop="0dp"
android:layout_centerHorizontal="true" />
<!-- Maze walls -->
<ImageView
android:layout_width="@dimen/wall_width"
android:layout_height="200dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:id="@+id/wall4"
android:background="#000000"
android:alpha="1"
android:layout_marginTop="10dp"
android:layout_marginLeft="120dp" />
<ImageView
android:layout_width="60dp"
android:layout_height="@dimen/wall_width"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:id="@+id/wall5"
android:background="#000000"
android:alpha="1"
android:layout_marginTop="205dp"
android:layout_marginLeft="121dp" />
<ImageView
android:layout_width="150dp"
android:layout_height="@dimen/wall_width"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:id="@+id/wall6"
android:background="#000000"
android:alpha="1"
android:layout_marginTop="205dp"
android:layout_marginLeft="225dp" />
<ImageView
android:layout_width="@dimen/wall_width"
android:layout_height="34dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:id="@+id/wall7"
android:background="#000000"
android:alpha="1"
android:layout_marginTop="175dp"
android:layout_marginLeft="225dp" />
<ImageView
android:layout_width="40dp"
android:layout_height="@dimen/wall_width"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:id="@+id/wall8"
android:background="#000000"
android:alpha="1"
android:layout_marginTop="175dp"
android:layout_marginLeft="189dp" />
<ImageView
android:layout_width="@dimen/wall_width"
android:layout_height="140dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:id="@+id/wall9"
android:background="#000000"
android:alpha="1"
android:layout_marginTop="39dp"
android:layout_marginLeft="189dp" />
<TextView
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="time: "
android:id="@+id/timeText"
android:layout_marginTop="280dp"
android:textSize="20sp"
android:gravity="center" />
</RelativeLayout>
【问题讨论】:
-
请附上你如何绘制它的代码。
-
@DavidMedenjak 这是 xml 代码
-
另外请附上您设置边距的代码。似乎您在运行时对某些部分执行此操作
-
我不相信我曾经设置过任何边距。这是整个 xml 文件。在一般代码中,我只使用此 xml 文件中的代码。