Member 13983723 Ответов: 0

(Andriod studio) рисование круга на imageview2 в тех же координатах, что и imageview1, если я нажимаю на место в imageview 1 и наоборот


I'm trying to make find the difference game app, but I never made anything like that and since I'm a new to development I'm stuck

well baby Steps are always needed to learn xD

**I read in some documentation that i have to get each ImageView height and width separately so when i touch imageView1 its coordinates can be set to ImageVIew2 and ViceVersa I MAYBE BE WRONG XD**

Right now I have a layout with 2 Images set vertically

    <RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".PlayActivity"
    android:id="@+id/hello1">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:id="@+id/hello">

        <ImageView
            android:id="@+id/image1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="@drawable/pic_9" />

        <ImageView
            android:id="@+id/image2"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="@drawable/pic_9a" />

    



    


What i want to do is if i tap a place in image1 a circle should be created on the same place in image2

after reading along a few things i have made a circle if i tap the layout but i am stuck after this i cant find what to do next maybe i cant find documentation related to my problems

    
    public class PlayActivity extends AppCompatActivity {

    RelativeLayout layout;
    float x = 0;
    float y = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_play);

        layout=(RelativeLayout) findViewById(R.id.hello1);
        layout.addView(new CustomView(PlayActivity.this));

    }

    public class CustomView extends View {

        Bitmap mBitmap;
        Paint paint;

        public CustomView(Context context) {
            super(context);
            mBitmap = Bitmap.createBitmap(400, 800, Bitmap.Config.ARGB_8888);
            paint = new Paint();
            paint.setColor(Color.RED);
            paint.setStyle(Paint.Style.FILL);
        }

        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            canvas.drawCircle(x, y, 50, paint);
        }

        public boolean onTouchEvent(MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                x = event.getX();
                y = event.getY();
                invalidate();
            }
            return false;
        }
    }}

**Right now i think my two ImageView arent separate because when i touch between the 2 images a circle is created which shouldn't since imageView1 ends im not sure if im thinking in right direction its just my guess on how should it work for the game to work I MAYBE BE WRONG XD**


I still have a long way to go, but I'm stuck here  
can anyone help?

i have provided little code as possible so anyone can check it

What I have tried:

I have tried many things as i explained above but since im new i might be doing it wrong so i dont want to mislead people by mentioning it

0 Ответов