[英]Adding dynamic views in android
I have the same problem as that of this adding views dynamically 我有一个与此动态添加视图相同的问题
I'm creating an application to tag photos in image using android. 我正在创建一个应用程序以使用android标记图像中的照片。
So once i tap at a position, i need to create a EditText where i can type. 因此,一旦我在某个位置点击,我就需要创建一个可以在其中键入内容的EditText。
I was able to do this, but the problem is when i edit the edittext, it is not invalidating the already existing data. 我能够做到这一点,但是问题是当我编辑edittext时,它不会使已经存在的数据无效。 It overlaps with the previous data that was present.
它与存在的先前数据重叠。
Here is how i inflate and add the 这是我如何充气并添加
public boolean onTouch(View v, MotionEvent event) {
//.....
frmLayout = (FrameLayout)findViewById(R.id.frameLayout);
frmLayout.setFocusable(true);
mInflater = LayoutInflater.from(getApplicationContext());
View view = mInflater.inflate(R.layout.tag_layout,null);
view.setX(event.getX());
view.setY(event.getY());
frmLayout.addView(view,250,250);
//....
}
tag_layout.xml tag_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello"
android:layout_alignParentLeft="true"
android:id="@+id/edittext1"
android:textColor="@android:color/black"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/edittext2"
android:layout_toRightOf="@id/edittext1"
android:text="D"
/>
</AbsoluteLayout>
TIA TIA
Inside that method,get the position of touch. 在该方法内,获取触摸位置。 3.Create new EditText EditText et= new EditText(context);
3.创建新的EditText EditText et = new EditText(context); MainLayout.addView(et);
MainLayout.addView(et);
and set the position of that EditText as position of Touch 并将该EditText的位置设置为Touch的位置
You can ask if you have any further queries! 您可以询问是否还有其他疑问!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.