2013-10-25 61 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上的位置!