【问题标题】:Java Android - cropping Image in ImageView [duplicate]Java Android - 在 ImageView 中裁剪图像 [重复]
【发布时间】:2013-08-16 01:06:37
【问题描述】:

我知道这应该很简单,但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>

【问题讨论】:

    标签: java android imageview crop


    【解决方案1】:

    尝试将android:adjustViewBounds="true"android:scaleType 属性一起添加到您的ImageView

    【讨论】:

    • 不会改变任何东西 - 它会尝试将所有 1950 像素放入 ImageView
    • @user2234594 你的ImageViews layout_width 参数是什么?
    • android:layout_width="match_parent" fill_parent 没有任何改变
    【解决方案2】:

    android:scaleType="matrix" 用于您的图像视图

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

    【讨论】:

    • 抱歉,我的图片没有裁剪。它仍然试图适应整个大图像
    • 你能发布你的xml吗
    • 我编辑了问题
    • 你是在用android:src来设置你的图片吗
    猜你喜欢
    • 1970-01-01
    • 2015-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-03
    相关资源
    最近更新 更多