如何在Android中的ImageView中仅显示图片宽度的一部分?

时间:2013-07-24 21:58:07

标签: android imageview

我在ImageView中有Image,因为我将它用作动画背景。如何显示图片以使其高度填充整个父级和宽度显示屏幕宽?

我尝试使用此代码进行此操作:

<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/background"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:src="@drawable/background"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"/>

</RelativeLayout>

但它不起作用。它只是在屏幕内部显示整个画面,将其宽度调整为屏幕的宽度。我在哪里误会?

1 个答案:

答案 0 :(得分:1)

你试过这样的事吗:

How to display a part of an image?

或者你可以使用android缩放

 Use android:scaleType="centerInside"