Android 在ImageView上拖放组件

Android 在ImageView上拖放组件,android,dynamically-generated,Android,Dynamically Generated,有谁能帮我知道如何在ImageView上动态添加TextField。并将它们拖动到图像视图上的任意位置,如我们所愿…我想这会对您有所帮助。在其中,我在fingure的触摸事件中拖动了图像和文本 查看代码您可以通过以下方式创建相对布局作为imageView的容器(或直接将图像设置为relativeLayout背景): <RelativeLayout android:layout_width="wrap_content" android:layout_h

有谁能帮我知道如何在
ImageView
上动态添加
TextField
。并将它们拖动到
图像视图上的任意位置,如我们所愿…

我想这会对您有所帮助。在其中,我在fingure的触摸事件中拖动了图像和文本


查看代码

您可以通过以下方式创建相对布局作为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>
关于拖放有很多关于。。看见


您想添加哪些组件?@Aksh您无法添加。将任何视图添加到ImageView中,因为它不是视图组,所以您可以创建一个自定义的可绘制类,该类可以向您创建的图像添加一些覆盖。想展示一下你们能告诉我另一个选择吗,带些样品code@Aksh看看我的答案如何扩展位图可绘制是的,我很健忘。我的意思是把它加到相对论中去!
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);