如何在图像视图的顶部设置自定义文本界面?

时间:2013-09-17 09:45:18

标签: android performance android-intent android-listview

我想在图片视图上实现自定义文字界面,触摸+拖动选择文字,而不是凸起键盘,用户可以在图片视图中输入自己的文字并将其保存在图片视图上。任何人都可以请帮忙? 这是我的完整图像活动类

  public class FullImageActivity extends Activity {

       @Override
        public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fullimage);

        // get intent data
        Intent i = getIntent();

        // Selected image id
        int position = i.getExtras().getInt("id");
        ImageAdapter imageAdapter = new ImageAdapter(this);

        ImageView imageView = (ImageView) findViewById(R.id.fullimage);
        imageView.setImageResource(imageAdapter.mThumbIds[position]);
    }

}

这是我的xml文件         

  <FrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content" >

  <ImageView
    android:id="@+id/fullimage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
     />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:text="yourtext" />
 </FrameLayout>

1 个答案:

答案 0 :(得分:2)

您可以覆盖ImageView并添加setText方法。

您在该方法中设置的文本可以通过将其添加到视图的onDrawMethod来添加到视图中。

通过捕获CustomImageView上的onTouchEvent,您可以在图像上移动文本。但你必须有两个活动。在您选择要显示/编辑的图像并键入文本的活动a后,您可以移动到下一个活动并在所选图像上显示文本。

http://bestsiteinthemultiverse.com/2008/11/android-graphics-example/ - 这应该向您展示如何在Canvas中绘制文本 这个http://www.vogella.com/articles/AndroidTouch/article.html应该让你开始关注触摸事件。

需要什么?