Trying to use custom image (topcrop) in android, but the application stops

I found the following message How to set a scalable image in topCrop

Based on the fact that I used the TopCropImageView class from https://gist.github.com/arriolac/3843346 , which extends ImageView

Below is my layout xml file

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <com.simha.quotes.TopCropImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageView23" android:src="@drawable/background" /> <TextView android:layout_width="wrap_content" android:layout_height="100dp" android:text="New Text" android:id="@+id/textView23" android:layout_gravity="center_horizontal" android:layout_marginBottom="33dp" android:layout_marginLeft="30dp" android:layout_marginStart="50dp" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:textColor="#ffffff" android:textSize="14sp" android:textStyle="bold" android:shadowColor="#000000" android:shadowDx="4" android:shadowDy="4" android:shadowRadius="4" /> </RelativeLayout> 

gradle compiles without errors. But when I use the application, and when I come to use the above layout. he stops saying something like "an application to unfortunately stop."

Is there anything that is missing or has the wrong approach.

+2
android-custom-view
source share
1 answer

I found a solution: .java does not use View 2 or 3 argument constructors; The XML attributes will not work added them to the TopCropImageView code, after which it worked.

 public TopCropImageView(Context context, AttributeSet attrs) { super(context, attrs); setScaleType(ScaleType.MATRIX); } public TopCropImageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setScaleType(ScaleType.MATRIX); } 
+3
source share

All Articles