when the user clicks on the button the same image will display again and again on multiple locations. I am using on touch listener to move images. that is working but I can't create multiple images with the same imageview or with for loop please help. This is the image I want to create multiple time This is my xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
android:orientation="vertical"
android:id="@+id/main_html"
tools:context="com.incubers.signondoc.ui.HtmlActivity">
<Button
android:id="@+id/save_edited"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
style="?android:button"
android:text="@string/hint_save" />
<com.github.barteksc.pdfviewer.PDFView
android:id="@+id/viewpdfHtml"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imageSign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/no_connection" />
</com.github.barteksc.pdfviewer.PDFView>`
This is my ontouchlistener for moving images and other code
ImageView imageView;
ViewGroup mainLayout;
private View.OnTouchListener onTouchListener() {
return (view, event) -> {
final int x = (int) event.getRawX();
final int y = (int) event.getRawY();
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
RelativeLayout.LayoutParams lParams = (RelativeLayout.LayoutParams)
view.getLayoutParams();
xDelta = x - lParams.leftMargin;
yDelta = y - lParams.topMargin;
break;
case MotionEvent.ACTION_UP:
float xD = event.getX();
float yD = event.getY();
DisplayMetrics displayMetrics = this.getResources().getDisplayMetrics();
float XDis = displayMetrics.xdpi;
float YDis = displayMetrics.ydpi;
finalX = xD/XDis*100;
finalY = yD/YDis*100;
break;
case MotionEvent.ACTION_MOVE:
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view
.getLayoutParams();
layoutParams.leftMargin = x - xDelta;
layoutParams.topMargin = y - yDelta;
layoutParams.rightMargin = 0;
layoutParams.bottomMargin = 0;
view.setLayoutParams(layoutParams);
break;
}
mainLayout.invalidate();
return true;
};
}
this is the button which should show images on click
buttonSign.setOnClickListener(view ->{
}
});