Android背景图片填充屏幕

kmb*_*b64 33 android android-layout

如何让我的相对布局显示我的图像视图,如下所示:

在此输入图像描述

而不是这个?:

在此输入图像描述

我希望我的布局尽可能多地显示图像并裁剪图像的外部,就像在桌面上将桌面背景图像设置为"填充"时一样:

在此输入图像描述

到目前为止我的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>
Run Code Online (Sandbox Code Playgroud)

小智 30

在imageview中添加缩放类型.有几种类型.你需要的是

android:scaleType="center"
Run Code Online (Sandbox Code Playgroud)

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


jee*_*eet 5

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"/>
Run Code Online (Sandbox Code Playgroud)