Java Android - 在ImageView中裁剪图像

6
我知道这应该很简单,但是android:scaleType="centerCrop"不能裁剪图像。
我有一张1950像素宽的图片,需要通过父元素的宽度进行裁剪。但是android:scaleType="centerCrop"不能裁剪图像。我需要在布局中做什么才能只显示前面的400像素,或者任何屏幕/父元素的宽度。
对于这个简单的问题,抱歉打扰了 - 尝试过谷歌搜索,只有复杂的问题。而且我是新手,请不要给我点踩)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rl1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background_color">

    <ImageView
            android:id="@+id/ver_bottompanelprayer"
            android:layout_width="match_parent"
            android:layout_height="227px"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:scaleType="matrix"

            android:background="@drawable/ver_bottom_panel_tiled_long" />

</RelativeLayout>
2个回答

1

使用android:scaleType="matrix"来设置您的ImageView

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/opLayout"
    android:layout_width="400px"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/bar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="matrix"
        android:src="@drawable/ic_launcher_web" />

</LinearLayout>

1
抱歉,这并不能裁剪我的图像。它仍然尝试适应整个大图像。 - user2234594
你能发布你的 XML 吗? - Arun C
1
你是否正在使用 android:src 来设置你的图片? - Arun C

1
尝试在您的ImageView中添加android:adjustViewBounds="true",以及android:scaleType属性。

1
仅翻译文本内容:不更改任何内容 - 它尝试将所有1950个像素适配到ImageView中。 - user2234594
@user2234594,你的ImageViewlayout_width参数是多少? - Boris Mocialov
android:layout_width="match_parent" fill_parent并没有改变任何东西。 - user2234594

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接