0

So I'm working on Pacman for Android as a learning exercise. I've got the background set in my activity layout, but I'm having trouble making the background fit properly.

I've tried centerCrop and fitXY, with different results, neither of which work exactly. I want to stretch the view to the dimensions of the screen. It appears however that the image view is restricted to the center, like I have 3 imageviews ... but I have only one.

Any thoughts? Do I have to do some of this in code?

Thanks!

<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:background="#000FFF"
tools:context="srg.pmd.GameActivity"
>
<ImageView
    android:id="@+id/emptyPacman"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/blank_screen"
    android:scaleType="fitXY"
    />

First screenshot is fitXY

fitXY result

Second is centerCrop

centerCrop result

ether_joe
  • 1,068
  • 1
  • 13
  • 32

2 Answers2

0

The image you are using must be 320x480 then only the image will fit the screen other wise it will get distorted here is a link for more info about the image size Android: Background Image Size (in Pixel) which Support All Devices .hope it works for u

Community
  • 1
  • 1
SAVVY
  • 55
  • 1
  • 10
  • thanks for your response savvy. I'm interested in stretching to fit -- but it seems like the options available don't work exactly. I don't mind distortion -- I just expected fitXY to, well, stretch to fit both X and Y. It seems to be stretching only on the Y axis though, which led me to post. – ether_joe May 20 '16 at 17:23
  • instead of setting image in src set the image in background hop it works – SAVVY May 20 '16 at 17:56
  • gave it a shot! Unfortunately same result :P I suspect the answer is manipulating the image view in code ... I'll look at it in a bit over the weekend. – ether_joe May 21 '16 at 03:13
0

Well, nuts to me. The actual png file was wrong -- it was a lot wider than I assumed. Taking a closer look with an image editor revealed the problem.

ether_joe
  • 1,068
  • 1
  • 13
  • 32