Android Cropping Drawable从顶部到适合ImageView

时间:2013-07-15 02:55:16

标签: android android-imageview android-image

问题描述: 我有一个ImageView,由于不同设备的高度变化,它的大小会发生变化。

目的: 我希望将drawable的底边与图像视图的底部保持一致,并从顶部裁剪其余部分。

我做了什么: 我尝试过使用centerCrop但它只从顶部和底部裁剪:

<ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/llHomeScreenButtonBar"
        android:layout_alignParentTop="true"
        android:scaleType="centerCrop"
        android:src="@drawable/bg_home" />

我还尝试从Chris Arriola

复制Extended ImageView类

但是,我遇到了eclipse的错误:

  

自定义视图CustomImageView未使用2或3参数的View构造函数; XML属性不起作用

XML代码片段如下所示:

    <com.misc.CustomImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/llHomeScreenButtonBar"
        android:layout_alignParentTop="true"        
        android:src="@drawable/bg_home" />

实现这一目标的最佳方式是什么?

谢谢!

1 个答案:

答案 0 :(得分:0)

实现2和3参数构造函数。

XML通胀过程不能使用单参数构造函数public CustomImageView(Context) .XML通胀使用另外两个构造函数中的一个,还有一个或两个参数。

请参阅https://stackoverflow.com/a/9195858/357951

相关问题