2013-10-25 60 views
0

动态视图我有同样的问题作为这一adding views dynamically添加android系统

我创建一个应用程序采用了android标记的图像照片。

所以一旦我点击一个位置,我需要创建一个EditText,我可以键入。

我能够做到这一点,但问题是当我编辑edittext时,它不会使已经存在的数据无效。它与之前存在的数据重叠。

这里是我膨胀并添加

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

<?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

+0

就像在这里注释.. AbsoluteLayout已被弃用。你应该使用一些其他的布局..只要这不是造成这个问题无论如何。 –

+0

@AndroSelva我想在他点击的位置创建一个新的视图。所以我去了绝对。有没有其他的布局,当我可以创建一个特定的(x,y) – siva

+0

可能是一个框架布局.. –

回答

0
  1. 呼叫对图像上抽头的方法。
  2. 在该方法中,获取触摸的位置。 3.创建新的EditText EditText et = new EditText(context); MainLayout.addView(et);

  3. ,并设置为触摸

你可以问,如果您有任何疑问的立场,即EditText上的位置!