Problem Description: I have an ImageView which changes in size due to changing heights of different devices.
Aim: I am looking to keep the bottom edge of the drawable in line with the bottom of the image view and crop the rest from the top.
What I've Done: I've tried using centerCrop but it only crops from top and bottom:
<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" />
I've also tried copying the Extended ImageView class from: Chris Arriola
However, I've encountered an error from eclipse saying:
Custom view CustomImageView is not using the 2- or 3-argument View constructors; XML attributes will not work
The XML code fragment looks like this:
<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" />
What's the best way to achieve this?
Thanks!
Implement the 2- and 3-argument constructors.
The one-argument constructor public CustomImageView(Context)
can't be used by the XML inflation process.. XML inflation uses one of the other two constructors, with one or two more arguments.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.