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
就像在这里注释.. AbsoluteLayout已被弃用。你应该使用一些其他的布局..只要这不是造成这个问题无论如何。 –
@AndroSelva我想在他点击的位置创建一个新的视图。所以我去了绝对。有没有其他的布局,当我可以创建一个特定的(x,y) – siva
可能是一个框架布局.. –