I am creating an Android application where the user draws some objects on the screen. One type of object is a Text object. The user creates an object by dragging his finger, and the object is displayed as a rectangle that can be moved / changed. When the user deletes the text object, I start a new action when the user enters the text, which I return using the onActivityResult method.
Now I want to show the text in the object. I can access materials like Rectangle coordinates, etc. From my text class. What I want to do essentially is to create a TextView (or EditText) programmatically and set its borders as the borders of my rectangle into which my object was drawn. Is there any way that can help me?
(another approach is to use the canvas.drawTextOnPath method in my text object, but this seems more complicated as my text can exit the object and I will also have to process multi-line lines)
Thank you in advance!
EDIT: attempt to use GAMA
protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch(requestCode) { case 1: if (resultCode == Activity.RESULT_OK) { String text=data.getStringExtra("text"); System.out.println(text); TextView tv=new TextView(this); //LayoutParams lp = new LayoutParams(new ViewGroup.MarginLayoutParams((int)texts.get(index).width,(int)texts.get(index).height)); LayoutParams lp = new LayoutParams(new ViewGroup.MarginLayoutParams(100,100)); //tv.setLayoutParams(lp); //lp.setMargins((int)texts.get(index).Sx, (int)texts.get(index).Sy, (int)texts.get(index).Lx, (int)texts.get(index).Ly); tv.setLayoutParams(lp); tv.setTextSize(10); tv.setTextColor(Color.RED); tv.setText(text); lp.setMargins(0,0,0,0); //tv.setVisibility(View.VISIBLE); System.out.println("got "+tv.getText()); } break; } }
both prints display the text as expected, but I canβt see anything on the screen (first I tried to set it in the lower left corner)
source share