问题描述:

I've had the same problem for a long time now, which is basically what the title says. I have drawn some pictures to visualize what I'm trying to achieve.

Picture of man on ground

So on this first pickture, we have a man(player) standing on the GROUND of the Background image. In a 1024x728 Device this player is positioned somewhere around the Screen Height - 120px. I wan't to support multiple screen resolutions, but when I run the App on a bigger screen, this happens of course:

picture of man not on ground

The height of the background is bigger, therefor the ground is futher away from the bottom and -120px is not enough.

(In the app; pictures are drawn with Canvas as bitmaps)

So my question is, how do I achieve to get this man to always have the position on the ground? What's best practise? And can you show me some examples?

Thanks a lot.

网友答案:

There are two aproaches:

1) Using RelativeLayout child of this layout can be specified in relation to other childern

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:paddingLeft="16dp"
   android:paddingRight="16dp" >

   <EditText
      android:id="@+id/name"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
     />

   <LinearLayout
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_below="@+id/name">  <<<< look at this

</RelativeLayout>

2) Using just added percentage support library. You can specify % position on the screen. Read this for it

相关阅读:
Top