在ImageView上拖放组件

时间:2014-02-12 08:34:25

标签: android dynamically-generated

任何人都可以帮助我了解如何在TextField动态添加ImageView。然后将它们拖到我们想要的ImageView上的任何位置......

2 个答案:

答案 0 :(得分:0)

我认为Drag and Drop Blog会对你有帮助。其中我在fingure的触摸事件中拖动图像和文本。

查看代码HERE

答案 1 :(得分: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

相关问题