Find the difference app android layout not working

  • Replies:0
  • OpenNot stickiedUnanswered
  • Forum posts: 1

Apr 6, 2018 10:16:13 AM via Website

I want to create a find the difference in 2 images kind of app in Native android.

I have done this using a Custom view with 2 images side by side and finding the touch positions (X,Y) of the image and it kind of works. But as soon as I try it on a different device the (X,Y) changes.

On one device the bitmap is (600 x 500) and the other it is (800 x 700). What can I do to get the aspect ratio same which is 6:5 in all devices?
Is there any alternate way to do this kind of App?

This is a part of my xml layout.

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:orientation="vertical">

<gamesforkids.coloring.games.multipleclickableex.CanvasView
    android:id="@+id/signature_canvas"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:background="@drawable/scene_2"
    />
    <ImageView
        android:id="@+id/iv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ring"
        android:visibility="invisible" />
    <ImageView
        android:id="@+id/iv_a"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ring"
        android:visibility="invisible" />

</FrameLayout>

This is my java onTouch code.

@Override
public boolean onTouch(View v, MotionEvent event) {

    switch (v.getId()) {

        case R.id.signature_canvas:

            x0 = event.getX();
            y0 = event.getY();

            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    CanvasView.startTouch(x0, y0);
                    break;
                case MotionEvent.ACTION_MOVE:
                    CanvasView.moveTouch(x0, y0);
                    break;
                case MotionEvent.ACTION_UP:
                    CanvasView.upTouch();

                    Toast.makeText(this, "X_Value_" + x0 + "_Y_Value_" + y0, Toast.LENGTH_SHORT).show();

                    if (x0 > MyConstant.x0_min && x0 < MyConstant.x0_max && y0 > MyConstant.y0_min && y0 < MyConstant.y0_max)

                    {

                        iv.setX(((MyConstant.x0_max+MyConstant.x0_min)/2));
                        iv.setY(((MyConstant.y0_max+MyConstant.y0_min)/2));
                        iv.setVisibility(View.VISIBLE);

                        iv1.setX(((MyConstant.x0_max+MyConstant.x0_min)/2));
                        iv1.setY(((MyConstant.y0_max+MyConstant.y0_min)/2));
                        iv1.setVisibility(View.VISIBLE);

                    }

                    if (x0 > MyConstant.x0_min1 && x0 < MyConstant.x0_max1 && y0 > MyConstant.y0_min1 && y0 < MyConstant.y0_max1)

                    {

                        iv_a.setX(((MyConstant.x0_max1+MyConstant.x0_min1)/2));
                        iv_a.setY(((MyConstant.y0_max1+MyConstant.y0_min1)/2));
                        iv_a.setVisibility(View.VISIBLE);

                        iv_a1.setX(((MyConstant.x0_max1+MyConstant.x0_min1)/2));
                        iv_a1.setY(((MyConstant.y0_max1+MyConstant.y0_min1)/2));
                        iv_a1.setVisibility(View.VISIBLE);

                    }
                    break;
            }

            break;

    }
    return true;

}

Screenshots of images of two different devices

image

image

Be the first to answer