Android 背景图片填充屏幕

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10679366/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 04:34:24  来源:igfitidea点击:

Android background Image to fill screen

androidandroid-layout

提问by kmb64

How do I get my relative layout to display my image view like this:

如何让我的相对布局像这样显示我的图像视图:

enter image description here

在此处输入图片说明

Instead of this?:

而不是这个?:

enter image description here

在此处输入图片说明

I want my layout to display as much of the image as it can and crop the outsides of the image, like when you're setting desktop background image to "Fill" in windows:

我希望我的布局尽可能多地显示图像并裁剪图像的外部,例如在 Windows 中将桌面背景图像设置为“填充”时:

enter image description here

在此处输入图片说明

My xml layout so far:

到目前为止我的 xml 布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" android:fitsSystemWindows="true" android:alwaysDrawnWithCache="false">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" android:src="@drawable/background_race_light"/>

    <LinearLayout
        android:id="@+id/linearLayout1"
        style="@style/SessionResumeBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TextView
            android:id="@+id/home_resumeSessionBar_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Medium Text"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <Button
            android:id="@+id/home_resumeSessionBar_buttonResume"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Resume" />
    </LinearLayout>





</RelativeLayout>

采纳答案by Phobos

Add a scale type to your imageview. There are several types. The one you need is

将比例类型添加到您的图像视图。有几种类型。你需要的是

android:scaleType="center"

This pagewill help explain all the different types.

页面将帮助解释所有不同的类型。

回答by jeet

Set the ImageViewlayout parameters to match_parentand set scale type to an appropriate scale type which fulfills your needs:

ImageView布局参数match_parent设置为,并将比例类型设置为满足您需求的适当比例类型:

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:scaleType="centerCrop"
    android:layout_alignParentTop="true" android:src="@drawable/background_race_light"/>

回答by Trikaldarshi

Set scalexy = truein ImageView

设置scalexy = trueImageView