0
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using NativeUiLib;
using Android.Graphics;

namespace Graf
{
    public class Program
    {
        public LinearLayout lin = new LinearLayout();
        public int screenWidth = 1080;
        public int screenHeight = 1920;

        public ImageView pic;

        public void Main()
        {
            Ui.RunOnUiThread(() => MainUi());

        }

        public void MainUi()
        {
            var slider = lin.AddSeekBar(true);
            slider.Max = 540;
            slider.Min = 1;
            pic = lin.AddImageView(true);
            pic.SetY(screenHeight / 2 - screenWidth / 2);
            pic.SetFrame(0, 200, 1080, 1280);
            lin.Show();

            slider.ProgressChanged += (e, s) =>
            {
                pic.SetImageBitmap(CreateImg(slider.Progress));
            };
        }

        private Bitmap CreateImg(float r)
        {
            Bitmap bitmap = Bitmap.CreateBitmap(1080, 1080, Bitmap.Config.Rgb565);
            Paint paint = new Paint();
            paint.SetARGB(255, 255, 0, 0);
            Canvas canvas = new Canvas(bitmap);
            canvas.DrawARGB(255, 255, 255, 255);
            canvas.DrawCircle(bitmap.Width / 2, bitmap.Height / 2, r, paint);
            canvas.DrawBitmap(bitmap, 0, 0, paint);
            return bitmap;
        }
    }
}

(31, 8): 'ImageView.SetFrame(int, int, int, int)' is inaccessible due to its protection level

I'm learning c# xamarin android. And I experience this problem, trying to edite ImageView object size and position. Can someone explain?

1 Answers1

0

setFrame is a protected method in ImageView, which means it can only be accessed by the ImageView itself or classes that inherit from it. That is why the compiler is telling you that the method is inaccessible.

If you want to set the size for the ImageView programatically you should look into using its Layout parameters (or its parents' parameters) as explained in this question

Daniel
  • 777
  • 9
  • 21