Android:处理多个屏幕的图像大小

标签 android image screen image-size

我发现用 Android 处理图像真的很难,我认为这是 Android 开发中最难的部分......

1) 我有一张图片,我希望它成为我的应用程序的背景,所以我这样做了

<?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。在某些(小)屏幕上仅显示部分背景。我怎么能说:我希望图像填满整个屏幕,即使图像比屏幕大也应该缩小图像以便我看到所有背景?

也许我应该放上我的背景而不是用它作为背景

<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>

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

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

<?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" >

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

最佳答案

Android 使用两个通用属性对设备屏幕进行分类:尺寸和密度。您应该预料到您的应用程序将安装在屏幕大小和密度各不相同的设备上。因此,您应该包括一些替代资源,以针对不同的屏幕尺寸和密度优化您的应用程序的外观。有四种广义尺寸:small、normal、large、xlarge和四种广义密度:low (ldpi)、medium (mdpi)、high (hdpi)、extra high (xhdpi)

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

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

参见 android.com's "Supporting Different Screens"文章了解更多信息。

关于Android:处理多个屏幕的图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14747489/

相关文章:

Android通知没有声音和振动

mysql - 为什么我的图像存储为 MySQL longblobs 仅部分显示?

javascript - 如何通过CropperJS获取裁剪图像的坐标?

java - Android 在屏幕更改时保存和恢复 ArrayList <Long>

iphone - 如何在 iPhone 5 上保留 iPhone 4- 格式化

android - 如何在Android应用程序构建中解析mapbox引用?

android - 通过将 proguard 规则映射文件上传到 google play 控制台来反混淆生产 Android 错误

java - 如何从android中的短信查询中分别获取一天中的时间,星期几和月份

javascript - tinyMCE 图像显示正确,但不更新 src

iphone - 如何防止 iOS 设备上的显示屏变暗和关闭?