2014-02-12 53 views
1

任何人都可以帮助我知道如何在ImageView上动态添加TextField。并将它们拖到我们想要的那个ImageView上的任何位置...在ImageView上拖放组件

回答

0

我认为Drag and Drop Blog会帮助你。其中我已经拖动图像以及文字都触摸事件的方向。

查看代码HERE

+0

很好,但我想在ImageView的添加成分没有布局... – Akshay

+0

你想要什么要添加的组件? – GrIsHu

+0

动态创建的TextView .. – Akshay

0

您可以创建一个相对布局为您的ImageView的容器(或直接设置你的RelativeLayout的背景图片)像这样:

<RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/relativeLayout"> 
     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/imageView" 
      android:src="@drawable/your_image" 
      android:layout_centerHorizontal="true" /> 
<RelativeLayout> 

和编程,你得到你的imageView并添加textView到:

RelativeLayout relativeLayout = (relativeLayout) findViewById(R.id.relativeLayout); 
ImageView iv_myImage = (ImageView) findViewById(R.id.imageView); 
// Create new textView 
TextView textView = new TextView(context); 
// Here set style on textView 
// Finally add textView to imageView 
relativeLayout.addView(textView); 

关于拖放有很多关于..的主题..见 http://www.techrepublic.com/blog/software-engineer/try-androids-useful-drag-and-drop-api/

drag and drop textview

+0

但是addView是ImageView的属性吗?我怀疑它.. – Akshay

+0

是的,我很健忘。我的意思是将它添加到relativeLayout! – marino