Создание отзывчивого прямоугольника большого размера в Xamarin. Android - PullRequest
1 голос
/ 29 января 2020

Я сделал прямоугольник в Xamarin. Android с помощью Camera View. Но есть много проблем, таких как -

  1. Не очень отзывчивый
  2. Отставание при перетаскивании углов

Мои попытки пока что в CameraLayout. xml

   <ImageView
        android:id="@+id/Center_Point_photo"
        android:layout_width="80px"
        android:layout_height="80px"
        android:src="@drawable/center_point"
        android:layout_marginTop="670px"
        android:layout_marginLeft="350px" />

    <ImageView
        android:id="@+id/Top_Left_photo"
        android:layout_width="50px"
        android:layout_height="50px"
        android:src="@drawable/top_left"
        android:layout_marginTop="600px"
        android:layout_marginLeft="250px" />
    <ImageView
        android:id="@+id/Top_Right_photo"
        android:layout_width="50px"
        android:layout_height="50px"
        android:src="@drawable/top_right"
        android:layout_marginTop="600px"
        android:layout_marginLeft="500px" />
    <ImageView
        android:id="@+id/Bottom_Left_photo"
        android:layout_width="50px"
        android:layout_height="50px"
        android:src="@drawable/bottom_left"
        android:layout_marginTop="750px"
        android:layout_marginLeft="250px" />
    <ImageView
        android:id="@+id/Bottom_Right_photo"
        android:layout_width="50px"
        android:layout_height="50px"
        android:src="@drawable/bottom_right"
        android:layout_marginTop="750px"
        android:layout_marginLeft="500px" />

Here is image

Вторая проблема при перетаскивании углов. Мой код для перетаскивания углов не сглаживается:

ImageView OCR_Rectangle;
ImageView OCR_Top_Left;
ImageView OCR_Top_Right;
ImageView OCR_Bottom_Left;
ImageView OCR_Bottom_Right;

int deltaX = (int)e.GetX() - lastX;
int deltaY = (int)e.GetY() - lastY;      
    centerX = (int)OCR_Rectangle.GetX() + OCR_Rectangle.Width / 2;
    centerY = (int)OCR_Rectangle.GetY() + OCR_Rectangle.Height / 2;
    if (((int)e.GetX() >= centerX) && ((int)e.GetY() >= centerY))
    {
    OCR_Rectangle.SetX(OCR_Rectangle.GetX() - deltaX );
    OCR_Rectangle.SetY(OCR_Rectangle.GetY() - deltaY * 2);
    OCR_Rectangle.LayoutParameters.Width += deltaX * 2;
    OCR_Rectangle.LayoutParameters.Height += deltaY * 4;   
    OCR_Top_Left.SetX(OCR_Rectangle.GetX());
    OCR_Top_Left.SetY(OCR_Rectangle.GetY());
    OCR_Top_Right.SetX(OCR_Rectangle.GetX() + OCR_Rectangle.Width - OCR_Top_Right.Width);
    OCR_Top_Right.SetY(OCR_Rectangle.GetY());
    OCR_Bottom_Left.SetX(OCR_Rectangle.GetX());
    OCR_Bottom_Left.SetY(OCR_Rectangle.GetY() + OCR_Rectangle.Height - OCR_Bottom_Left.Height);
    OCR_Bottom_Right.SetX(OCR_Rectangle.GetX() + OCR_Rectangle.Width - OCR_Bottom_Right.Width);
    OCR_Bottom_Right.SetY(OCR_Rectangle.GetY() + OCR_Rectangle.Height - OCR_Bottom_Right.Height);
    } 
    OCR_Rectangle.RequestLayout();    
    lastX = (int)e.GetX();
    lastY = (int)e.GetY();

Меня вдохновляет приложение Microsoft Math ссылка здесь Так что я хочу сделать что-то подобное

Their rectangle Любая помощь будет оценена.

Первая попытка enter image description here

1 Ответ

1 голос
/ 30 января 2020

Вы должны использовать FrameLayout для центрирования элементов и размещения их в правильных положениях в этом проекте.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    
    android:layout_width="match_parent"
    android:background="#fff"
    android:layout_height="match_parent">  
    <TextView
        android:text="Text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:textColor="@android:color/holo_red_light"
        android:minWidth="25px"
        android:minHeight="25px"
        android:id="@+id/textView1"
        android:layout_gravity="left|top" />
    <ImageView
        android:src="@android:drawable/ic_menu_gallery"
        android:layout_margin="10dp"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:id="@+id/imageView1"
        android:layout_gravity="right|top" />
    <FrameLayout
        android:minWidth="25px"
        android:minHeight="25px"
        android:layout_width="200dp"
        android:layout_height="150dp"
        android:id="@+id/frameLayout1"
        android:layout_gravity="center" >
        <ImageView
            android:background="#000"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:id="@+id/imageView2"
            android:layout_gravity="top|left" />
        <ImageView
            android:background="#000"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:id="@+id/imageView3"
            android:layout_gravity="bottom|left" />
        <ImageView
            android:background="#000"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:id="@+id/imageView4"
            android:layout_gravity="top|right" />
        <ImageView
            android:background="#000"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:id="@+id/imageView5"
            android:layout_gravity="bottom|right" />
        <ImageView
            android:background="#000"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:id="@+id/imageView6"
            android:layout_gravity="center" />
    </FrameLayout>

</FrameLayout>

изображение показывает результат, я использовал цвет фона для отображения положения изображений

...