展开一个EditText动态

编程入门 行业动态 更新时间:2024-10-28 17:25:43
本文介绍了展开一个EditText动态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我愿做以下Android上:

I would like to do the following on Android:

  • 单击一个图像 - >在当场感动的图标应该出现
  • 当我再次点击那个地方,一个EditText应该出现
  • 当我的东西类型本应该的EditText动态地扩展
  • 原始图像应保存与EditText上和我在键入的文本
  • 什么是实现,最好的方法是什么?

    What would be the best way to accomplish that?

    要我所知的图像可被设置为onClickListener / onTouchListener,一旦的onClick / onTouch被调用时,我应该能够将图标添加到该位置,其中图标的图像并设定为onTouchListener作为好。当我点击了图片上,一个EditText应该出现 - 不知道如何使动态虽然它扩大?一旦文本输入和一个按钮后,整个图像 - 与的EditText文本 - 应保存 - 我会怎么做呢?在画布上画出?

    To my knowledge the image can be set to an onClickListener/onTouchListener, and once onClick/onTouch is called, I should be able to add an icon to that location, where the icon is an image and is set to an onTouchListener as well. When I click on that image, an edittext should appear - not sure how to make it expand dynamically though? Once the text is entered and a button is clicked, the entire image - with the text in the edittext - should be saved - how would I do that? Draw on a canvas?

    帮助将是非常美联社preciated! :)

    Help would be highly appreciated! :)

    推荐答案

    第1步

    您视图应该是一个的RelativeLayout内部,以便将它们彼此的顶部。当你preSS您的ImageView,小单将被设置为可见(它必须是XML文件或编程内不可见)。

    Your Views should be inside a RelativeLayout in order to place them top of each other. When you press your ImageView, small one will be set to Visible (it must be invisible inside xml file or programmatically).

    imgV.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { imageViewButton.setVisibility(View.VISIBLE); } });

    第2步

    在preSS小的图像,会的EditText变得可见。同上instucted。

    When you press small image, EditText will become visible. Same as instucted above.

    imageViewButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { editText.setVisibility(View.VISIBLE); } });

    第3步

    在打字的时候,如果你设置宽度match_parent和高度WRAP_CONTENT你的EditText自动扩展。

    Your EditText expands automatically when typing if you set width to match_parent and height to wrap_content.

    <EditText android:id="@+id/editText1" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" > </EditText>

    第四步

    当您想要保存您的布局,在你的onClick事件实现这一点。 (在下面的例子中,它是一个的LinearLayout,但你将有一个RelativeLayout的,我想你可以根据自己的需要改变它)

    When you want to save your Layout, implement this in your onClick event. (In the example below, it is a LinearLayout but you will have a RelativeLayout, I suppose you can change it according to your needs)

    据对How到布局视图图像或PDF格式保存到SD卡中的Andr​​oid?

    添加权限在manifest文件

    Add permission in the manifest file

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    使用以下

    LinearLayout content = findViewById(R.id.rlid); content.setDrawingCacheEnabled(true); Bitmap bitmap = content.getDrawingCache(); File file,f; if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) { file =new File(android.os.Environment.getExternalStorageDirectory(),"TTImages_cache"); if(!file.exists()) { file.mkdirs(); } f = new File(file.getAbsolutePath()+file.seperator+ "filename"+".png"); } FileOutputStream ostream = new FileOutputStream(f); bitmappress(CompressFormat.PNG, 10, ostream); ostream.close(); } catch (Exception e){ e.printStackTrace(); }

    更多推荐

    展开一个EditText动态

    本文发布于:2023-11-26 12:20:24,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1633911.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:动态   EditText

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!