Android:处理多个屏幕的图像大小 [英] Android: Handling images size for multiple screens

查看:140
本文介绍了Android:处理多个屏幕的图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得用Android处理图片真的很难,我认为这是Android开发中最困难的部分......

I find it really hard to handle images with Android, I think it's the hardest part of Android development...

1)我有一张图片,我想要它是我的应用程序的背景所以我做了

1) I have an image, I want it to be the background of my application so I do

<?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="fill_parent"
    android:layout_height="fill_parent"
    tools:context=".MainActivity" 
    android:background="@drawable/accueil">
</RelativeLayout>

背景应该填满整个屏幕,但不是cas。某些(小)屏幕上仅显示部分背景。我怎么能说:我希望图像填满所有屏幕,即使图像比屏幕更大,图像应该减少,所以我看到所有的背景?

The background should fill the entire screen but it's not the cas. Only a part of the background is shown on some (small) screens. How could I say: I want the image to fill all the screen even if the image is bigger then the screen the image should be reduced so I see all the background?

也许我应该把我的背景而不是用作背景

Maybe I should put my background instead of using it as a background

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    tools:context=".MainActivity">


       <ImageView
           android:id="@+id/imageView1"
           android:layout_width="500dp"
           android:layout_height="500dp"
           android:adjustViewBounds="false"
           android:src="@drawable/accueil" />

</RelativeLayout>

然而在某些设备中,图像有点裁剪。

Yet in some devices the image is a bit cropped.

2)我必须在另一个布局中放置一个布局,但我希望它的位置是精确的,它的宽度相对于父布局。然而,如果我这样做

2) I have to place a layout in another layout but I want its position to be precise, its width to be relative to the parent layout. Yet if I do

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/fond">

 <LinearLayout
     android:layout_width="300dp"
     android:layout_height="350dp"
     android:layout_marginTop="20dp"
     android:background="@drawable/fondshare"
     android:orientation="vertical" >

你可以看到结果不是我预期的
(线性布局是矩形带笑脸和所有按钮)

you can see the result is not what I expected (the linear layout being the rectangle with the smiley and all the buttons)

推荐答案

Android使用两个常规属性对设备屏幕进行分类:大小和密度。您应该期望您的应用程序将安装在屏幕尺寸和密度各不相同的设备上。因此,您应该包含一些替代资源,以针对不同的屏幕尺寸和密度优化应用的外观。有四种广义尺寸:小,普通,大,xlarge和四种广义密度:低(ldpi),中(mdpi),高(hdpi),超高(xhdpi)

Android categorizes device screens using two general properties: size and density. You should expect that your app will be installed on devices with screens that range in both size and density. As such, you should include some alternative resources that optimize your app’s appearance for different screen sizes and densities. There are four generalized sizes: small, normal, large, xlargeAnd four generalized densities: low (ldpi), medium (mdpi), high (hdpi), extra high (xhdpi)

要声明您想要用于不同屏幕的不同布局和位图,您必须将这些替代资源放在不同的目录中,类似于您对不同语言字符串的操作方式。

To declare different layouts and bitmaps you'd like to use for different screens, you must place these alternative resources in separate directories, similar to how you do for different language strings.

另请注意,屏幕方向(横向或纵向)被视为屏幕尺寸的变体,因此许多应用应修改布局以优化每个方向的用户体验。

Also be aware that the screens orientation (landscape or portrait) is considered a variation of screen size, so many apps should revise the layout to optimize the user experience in each orientation.

请参阅 android.com的支持不同的屏幕文章了解更多信息。

See android.com's "Supporting Different Screens" article for more information.

这篇关于Android:处理多个屏幕的图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆