开发者

Best fit the larger image into android device?

I have a larger image of 1024 x 768. When the image is displayed in the android device as the background image then it gets compressed. Is there any way that the image can be displayed properly in all screen resolution?


<RelativeLayout
 xmlns:android="http://schemas.android.com/apk/开发者_StackOverflowres/android"
 android:layout_width = "fill_parent"
 android:layout_height = "fill_parent"
 android:background = "@drawable/titlepage">
</RelativeLayout>

This is the code that I am using for setting the background image. But since the image is quite large it appears to be compressed when viewed on emulator or device.

Any help will be just great.


You are talking about multiple screen support. You need to make 3 types of images, HDPI, MDPI and LDPI. They have all different aspect ratios as well as different sizes.

Check out my tutorial on this subject, should explain everything.

http://wonton-games.blogspot.com/2010/07/tutorial-multiple-screen-support.html

or a simpler method if you just want to keep your aspect ratio is in your xml file using imageView do this

<ImageView
        android:id="@+id/background"
        android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/background"
            android:adjustViewBounds="true">
 </ImageView>

What this does is keep the aspect ratio of the image and fit it to the screen. You will get bars on either side if the aspect ratio doesn't match but this is just a quick shortcut way. You might have to play with layout_width/height to make it fit properly.


What you require is to maintain the resolution of the image, that would be the width:height ratio of the image. i am afraid for a 1024*768 the ratio is 1.33 , such image is meant for desktops. usually mobile devices have smaller ratio (w:h). eg: for Samsung galxy S , it would be 0.5, for Xperia X10, HTC Incredible, it would be 0.562. Android device screen sizes may vary. You need to have a suitable version of your image for each mdpi, ldpi and hdpi versions. Even then there is no guarantee that the image aspect ratio will be maintained. Better still have your image to be a 9 patch image, where you can define which part of the image should be stretched and which should be not, here you can preerve important part of the image.


Make an xml drawable file for the bitmap. You can change the gravity to "fill" You will still have issues with screens that are a different aspect ratio, but you can experiment with clamping, tiling, etc to get the look you want. http://developer.android.com/guide/topics/resources/drawable-resource.html#bitmap-element

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜