I created the layout in Platforms/Android/Resources/layout/activity_crop_image.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.canhub.cropper.CropImageView
android:id="@+id/cropImageView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Then i tried to get this view using this example:
using Android.App;
using Android.Content;
using Com.Canhub.Cropper;
namespace Android.Image.Cropper
{
public class Instance
{
CropImageView cropImageView;
void CropImage()
{
Context context = App.Application.Context;
Activity? activity = Platform.CurrentActivity;
if (activity != null) throw new Exception("Activity is null");
// Null here
cropImageView = (CropImageView)activity.FindViewById(activity.Resources.GetIdentifier("cropImageView", "id", activity.PackageName));
Console.WriteLine($"[Image Cropper] {cropImageView}");
}
}
}
Why the view is always nulls?
2