35

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:

enter image description here

My xml layout so far:

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

3 回答 3

34

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

android:scaleType="center"

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

于 2012-05-21T04:09:46.970 回答
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"/>
于 2012-05-21T04:17:37.043 回答
0

设置scalexy = trueImageView

于 2012-05-21T04:07:21.487 回答