0

So I have this canvas on where I paint bitmaps

An example would be a bitmap as a background.. so I will make this full screen on my 533x320 dip Samsung S2

So, when I load this same app on a, lets say, HTC with 480x320 dip.. my background image will now be larger then the screen - how is this normally handled?

I know some would might answer that I can just check the DIP sizes and use that.. which would also work for this background image.. but what about the 10 chess pieces I have where one of them is not out of the screen because it extends the 480dp of the HTC but works great on my 533dp S2?

How is this normally handled?

Biskoppen
  • 37
  • 5

2 Answers2

0

There are lot of ways to do that. Make sure you always use fill_parent or wrap_Content for your width and height attributes. In case of percentage based width's use LinearLayout for your layouts and use Layout_weight attribute for giving the width or height.

Remember to give width or height as 0dp if you are using layout weight attribute.

san
  • 1,845
  • 13
  • 23
0

The way I did it is to make a drawable for the background /drawable/backrepeat.xml that repeats an image (metalgrid.jpg) in both directions.

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/metalgrid"
android:tileMode="repeat"
android:dither="true" />

Then I have a style

<style name="page_background_gen">
    <item name="android:background">@drawable/backrepeat</item>
</style>

And then I use that style in my layout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" 
android:id="@+id/relativeLayout1" 
style="@style/page_background_gen"
android:layout_width="fill_parent">
....
</RelativeLayout>

This will fill the background with a repeated image without messign with the scale of the image.

Daniel Neilsen
  • 33
  • 1
  • 1
  • 3
  • Thanks Daniel, but that wont work when using a canvas to draw bitmap sprites on. ( Btw, if you would like another Android dane on ICQ to share thoughts with feel free to add me : 596870374 ) – Biskoppen Jan 06 '12 at 03:08