绘制视图中的XML图像 [英] Draw view on Image within xml

查看:106
本文介绍了绘制视图中的XML图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能帮助我如何绘制一个小矩形图像的顶部安卓分享你的知识。 我有main.xml中也有一些小部件。就在顶部,有一个形象,我想画一个矩形上的图像,并同时显示,而应用程序正在运行。

下面是我的XML文件是这样的:

 < XML版本=1.0编码=UTF-8&GT?;
    < TableLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:方向=垂直
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:layout_margin =5px的机器人:填充=20像素>
     < ImageView的
    机器人:ID =@ + ID / myImageView
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:SRC =@可绘制/正弦波/>
    <的TableRow>


    < /的TableRow>

    <的TableRow>
            < TextView的Andr​​oid版本:文本=00:00
                机器人:ID =@ + ID / TextView02
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_weight =1
                机器人:paddingBottom会=30dip

                机器人:重力=中心>
            < / TextView的>
    < /的TableRow>
    <的TableRow安卓重力=中心>

            <按钮的android:文本=开始
                    机器人:ID =@ + ID / btnStart
                    机器人:layout_width =WRAP_CONTENT
                    机器人:layout_height =WRAP_CONTENT
                    机器人:填充=20像素
                    >
            < /按钮>



            <按钮的android:文本=停止
                    机器人:ID =@ + ID / btnStop
                    机器人:layout_width =WRAP_CONTENT
                    机器人:layout_height =WRAP_CONTENT
                    机器人:填充=20像素
                    >
            < /按钮>

    < /的TableRow>
    <的TableRow>
            < TextView的Andr​​oid版本:文本=
                机器人:ID =@ + ID / TextView01
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:以下属性来=5像素
机器人:paddingRight =5像素
机器人:paddingTop =10px的
机器人:paddingBottom会=10px的

                >
            < / TextView的>

     < /的TableRow>
    <的TableRow>
            <按钮的android:文本=静音电话
                    机器人:ID =@ + ID / Button01
                    机器人:layout_width =WRAP_CONTENT
                    机器人:layout_height =WRAP_CONTENT
                    机器人:重力=中心
                    机器人:paddingBottom会=10dip
                >
            < /按钮>
    < /的TableRow>
    <的TableRow>
            <按钮
                机器人:文本=设置
                机器人:ID =@ + ID / btnClick
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:重力=中心
                机器人:paddingTop =30dip
            />
    < /的TableRow>

< / TableLayout>
 

解决方案

不要使用标准的ImageView了点。创建你自己的类扩展视图。然后覆盖draw()方法。在那里,您可以显示图像,做你想做,包括绘制矩形的东西。

can you help me by sharing your knowledge on how to draw a small rectangle on top of image in android. I have main.xml and there are some widgets. right at top, there is a image and I would like to draw a rectangle on that Image and display both while app is running.

Here is how my xml file looks like:

   <?xml version="1.0" encoding="utf-8"?>
    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_margin="5px" android:padding="20px">
     <ImageView
    android:id="@+id/myImageView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/sinewave"/>
    <TableRow>


    </TableRow>

    <TableRow>    
            <TextView android:text="00:00" 
                android:id="@+id/TextView02" 
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:paddingBottom="30dip"

                android:gravity="center">
            </TextView>      
    </TableRow>
    <TableRow android:gravity="center">

            <Button android:text="Start" 
                    android:id="@+id/btnStart" 
                    android:layout_width="wrap_content" 
                    android:layout_height="wrap_content" 
                    android:padding="20px"
                    >
            </Button>



            <Button android:text="Stop" 
                    android:id="@+id/btnStop" 
                    android:layout_width="wrap_content"  
                    android:layout_height="wrap_content" 
                    android:padding="20px"
                    >
            </Button>

    </TableRow>
    <TableRow>
            <TextView android:text=""
                android:id="@+id/TextView01"
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:paddingLeft="5px"
android:paddingRight="5px"
android:paddingTop="10px"
android:paddingBottom="10px"

                >
            </TextView>

     </TableRow>
    <TableRow>   
            <Button android:text="Mute Phone" 
                    android:id="@+id/Button01" 
                    android:layout_width="wrap_content" 
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:paddingBottom="10dip"
                >
            </Button>
    </TableRow>
    <TableRow>
            <Button 
                android:text="Settings"
                android:id ="@+id/btnClick"
                android:layout_width="wrap_content" 
                android:layout_height="wrap_content"
                android:gravity="center"
                android:paddingTop="30dip"
            />
    </TableRow>

</TableLayout>

解决方案

Don't use the standard ImageView for that. Create your own class extending View. Then override the draw() method. There you can display the image and do all the stuff you want including drawing the rectangle.

这篇关于绘制视图中的XML图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆