求助:用Paint绘制的小游戏在乞丐模拟器小游戏不显示图像

模拟器为密封式加固铝板结构,安装在托架左侧,也就是电气柜左下角。模拟器的外形见图30所示。模拟器的外形涂成珍珠色,其余外表面涂成苹果绿色 的翻译是:Simulator as the seal of reinforced aluminum plates, installed in the left side of the Bay, that is, left corner of the control cabinet. Simulator of shape shown in Figure 30. Simulation of paint appearance for Pearlescent, remaining outer surface paint Apple green 中文翻译英文意思,翻译英语
请在下面的文本框内输入文字,然后点击开始翻译按钮进行翻译,如果您看不到结果,请重新翻译!
模拟器为密封式加固铝板结构,安装在托架左侧,也就是电气柜左下角。模拟器的外形见图30所示。模拟器的外形涂成珍珠色,其余外表面涂成苹果绿色
选择语言:从
罗马尼亚语
罗马尼亚语
Simulator is sealed reinforced aluminum structure, installed in the bracket on the left, lower left corner is the electrical cabinet. Figure 30 shows the shape of the simulator. Simulator shape painted pearl color, top coat into the rest of the appearance of green apple
Simulator as the seal of reinforced aluminum plates, installed in the left side of the Bay, that is, left corner of the control cabinet. Simulator of shape shown in Figure 30. Simulation of paint appearance for Pearlescent, remaining outer surface paint Apple green
Simulator as the seal of reinforced aluminum plates, installed in the left side of the Bay, that is, left corner of the control cabinet. Simulator of shape shown in Figure 30. Simulation of paint appearance for Pearlescent, remaining outer surface paint Apple green
emulator for sealed reinforced aluminum structure, installation, that is left in cradles electric container bottom-left corner. emulator as shown in Figure see Figure 30. emulator painted Pearl color, appearance of the remaining outer surface painted apple green
The simulator for the sealed reinforcement aluminum sheet structure, installs left side of the bracket, also is the electricity wind chest left bottom.The simulator contour see Figure 30 to show.The simulator contour spreads the pearl, other outside surfaces spread the apple green
相关内容&a"You know who that is?" barber Anthony Clyburn asked in a tone reserved for the most awesome neighborhood characters, such as ball players and ex-convicts. “您知道谁那是?” 理发师安东尼在口气要求的Clyburn预留为最令人敬畏的邻里字符,例如球球员和前囚犯。 & aPlastic chess-pieces delivered in a polybag to Hong Kong. 塑料棋片断零件渴望诅咒在聚乙烯薄膜袋向香港。 & aThe relationship between the number of teams individuals are members of and productivity at
the individual and team levels is curvilinear 队个体之间的数量的关系是成员,并且生产力在个体和队水平曲线 & aперевести
текст с английского на русский 翻译文本从英语成俄国人 & awhiskey 威士忌酒 & a他们的讨论 Their discussion & aassembly and disassembly 汇编和拆卸 & a除了睡觉什么都不想做 Except sleeps anything not to want to do & a可以买到当地买不到的商品 May buy the commodity which the locality cannot buy & a有些学生早上不吃饭就匆忙去上学 Some students early morning do not eat meal hurriedly go to school & a中国的教育政策是“素质教育”。素质教育是一全面提高公民思想品德,提高科学文化和身体心理劳动技能素质培养能力,发展个性为目的的基础教育,但不能培养学生的创新意识 China's education policy is “the education for all-around development”.The education for all-around development is one enhances the citizen thought personal character comprehensively, enhances scientific cultural and bodily psychology work skill quality raise ability, the development individuality f & a应用文体翻译 Application literary style translation & abecause there has a saying 因为那里有一个说法 & acommercial
resdential 商业resdential & aメイは、私はあなたを愛し、あなたを愛し、あなたが私のすべてである、私はあなたに私の愛を与えていない、 关于5月,至于为我亲爱您,亲爱您,您是我一切,我未给我的爱您, & aMany people think that Sydney is one of the most attractive cities in the world . 许多人认为悉尼是其中一个最有吸引力的城市在世界上。 & ain you bump 在您爆沸 & a开设律师事务所 Opens the law office & apremlum
sltes premlum sltes & a提醒我十分钟后洗澡 After reminds my ten minutes to take a bath & aUnsubscribe I Terms of Use I Privacy Policy I Support 取消预订用途I我支持的隐私权政策的I期限 & a我的游戏公会 正在翻译,请等待... & a这是我们的产品模板 This is our product template & ainvestigator,annoucer,offier,sir sir to lie 调查员, annoucer, offier,说谎的先生先生 & a留园 Keeps the garden & a我要你生生世世爱我!永远不会和别人在一起!背叛我,你得死!把我的爱给你!让你永远痛苦! 私は生成の後であなたの生成に私を愛してほしい! 同じところの他の決して缶! 私をの死ななければならない裏切る! 鉱山愛を与える! 割り当てられる永久に苦痛がありなさい!
& aif you will let me reddem myself i'll be here if you're ever in need of me 如果您将让我reddem我这里将在,如果您是需要我 & achangedinto vapor changedinto蒸气 & aAnother difference between U.S. and non-U.S. stocks is that most non-U.S. stocks trade in the U.S. in the form of American Depositary Receipts (ADRs). ADRs are derivative instruments representing claims on the home market ordinary shares. A depositary bank (e.g.,
& a你提到的 You mention & aAUST L 正在翻译,请等待... & aby the end of 2002 to complete the network of experimental tests has been opened one after another business. 到2002年底完成实验性测试网络是逐个被打开的事务。 & a人们给它起了个名字'泉城' 正在翻译,请等待... & aReset Password or Unlock Apple ID 重新设置密码或打开苹果计算机公司ID & arelated to tumorigenesis can theoretically be iden- 与tumorigenesis相关可能理论上是iden- & a私下里诋毁某人 正在翻译,请等待... & a我想要一个知己陪伴我在我需要的时候 I want a friend to accompany me the time which needs in me & aPhenomena and Processes 现象和过程 & a多希望你能在我身边 ?? ?? ?? ?? ?? ? & ais induced in 导致 & afllowing fllowing & a严重影响了BHE生产的发展 Has affected the BHE production development seriously & aGentlemen, FYI. I don't recall the name of the fcty that made the Clementia style for Kohl's, but I want whoever was responsible for this fcty to send me copies of the reports that contain the results of the heel attachment tests that were performed on these shoes while they were being made asap. 先生们, FYI。 我不召回名字的fcty做Clementia样式为科尔的,但我想要谁负责对fcty的此送我包含脚跟附件试飞的结果在这些鞋子将执行报告的拷贝,当他们尽快时被做。 & a我爱你,可是我却有一种我一个人在走夜路的感觉,你并不在我身边 I love you, but I have one kind of me in to walk actually the night of road feeling, you not side me & a机组搬运应请参考文件1300-G18-PME043-1001 The unit transports should invite reference file 1300-G18-PME043-1001 & a我们应该做好自己的事 正在翻译,请等待... & a以下从5个方面证明。 Following from 5 aspect proofs. & aPlease consider 2 versions, simple and thermic. 请考虑2个版本,简单和热。 & aSelect the REBOOT turboIP button to reboot the unit and 选择重新起动turboIP按钮重新起动单位和 & aIf it is not the case already 如果它已经不是实际情形 & aThe initiatives have been 4-5 provinces and cities of the operator of a positive response and cooperation shown by the urgent desire. 主动性是迫切欲望和合作的显示的操作员4-5个省和城市积极反应。 & aWASHDARK COLOURS WASHDARK颜色 & aMbanoson 正在翻译,请等待... & aWaiting for server Waiting for server & a在保证营养的前提下 In under guarantee nutrition premise & a模拟器为密封式加固铝板结构,安装在托架左侧,也就是电气柜左下角。模拟器的外形见图30所示。模拟器的外形涂成珍珠色,其余外表面涂成苹果绿色 The simulator for the sealed reinforcement aluminum sheet structure, installs left side of the bracket, also is the electricity wind chest left bottom.The simulator contour see Figure 30 to show.The simulator contour spreads the pearl, other outside surfaces spread the apple green &他的最新文章
他的热门文章
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)三角形无法在android模拟器中显示!怎么解决?、_百度知道
三角形无法在android模拟器中显示!怎么解决?、
package com.example.
import android.os.B
import android.app.A
import android.content.C
import android.graphics.C
import android.graphics.C
import android.graphics.P
import android.graphi...
我有更好的答案
&&// TODO Auto-generated method stub&&&nbsp@Override&&&&&&&&protected void onDraw(Canvas canvas)&&&&&&&&{&&&&&&nbsp.lineTo(50.close();&&super.setColor(Color.GREEN);&nbsp, 20);&&&&&&&&&&&&&&&&&&paint.onDraw(canvas);&&&&&&&&&&&&&nbsp.lineTo(10;&Paint paint = new Paint();Path path = new Path();&&&&&&&&&&&&&&nbsp, 50);&&&&&&&&&&&&&&&&&&&&&&&&&&&&&nbsp, 50);&&&&&&&&&&&&&nbsp.BLUE);&&&&&&&&nbsp.moveTo(10;&&&&&&nbsp.drawColor(C&&&&&&&&&&&&&&&&nbsp
这什么意思??
把你代码中的onDraw方法,用我的替换就可以了。
你能说说我出错在哪里吗??谢谢!
super.onDraw(canvas); 你少了这句,父类方法中有大量绘图的基础,而你没有继承使用。
OnDraw(Canvas
canvas){super.onDraw(canvas);canvas.drawColor(Color.BLUE);Paint paint=new Paint();paint.setColor(Color.GREEN);Path
Path(); path.moveTo(10, 20);
path.lineTo(10, 50);
path.lineTo(50, 50);path.close();canvas.drawPath(path, paint);}我将我的代码中加上super.onDraw(canvas);还是不能显示!
OnDraw(Canvas
改为 onDraw(Canvas
,大小写也错了。
非常感谢!能否加Q以后多交流!
采纳率:60%
来自团队:
为您推荐:
其他类似问题
您可能关注的内容
android模拟器的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。谷普下载-免费软件,绿色软件,最快最安全的软件下载站 |
1234软件教程
最新资讯软件下载手机应用好玩游戏8月7日又到了立秋,一般年轻人就认为,热天快过去了,这可不对,要知道秋老虎让人小觑不得。这秋老虎就...
装机软件手机工具游戏下载聊天交友网络工具网络电视播放器输入法办公处理杀毒软件图像处理游戏平台其他常用聊天交友网络应用网络电视播放器手机输入办公应用安全杀毒图像相机手机工具其他应用即时战略赛车游戏动作射击智力游戏冒险游戏角色扮演趣味游戏模拟器类棋牌游戏游戏工具电脑常识如果用户希望在Word2010文档中创建链接向其他...
瑞典网站PocketPC.ch on声称其已经看到了最新...
本文的安装环境以及使用到的软件信息如下: ...
简介:用SharePoint代码加实施的方式,完成类...
Mac系统升级10.11.4软件无法登录怎么办?本月...
下载排行榜19340460次下载
29140460次下载
39040042次下载
47480866次下载
53242341次下载
62896982次下载
72797728次下载
82703182次下载
92703182次下载
101925557次下载
手机游戏 |
| 热门游戏热门游戏手机游戏排行1
手机软件 |
| 常用软件常用软件手机软件排行1
友情链接:
资讯中心:程序写累了,就来玩玩酷跑小游戏吧,嘿嘿。
雨松MOMO送你一首歌曲,嘿嘿。
Android Shape渲染的使用(经典,学习研究不后悔)(二十八)
Android Shape渲染的使用(经典,学习研究不后悔)(二十八)
围观19983次
编辑日期: 字体:
好久都没有写博文了,感觉自己变懒了,真对不起…-_-…
也有部分原因是因为我想写的东西网上已经有了,再加上还有很多方面小马我也正在学习,所以….这段时间一直暂停更新我的博客文章,看到博客的访问量一天天的增加,很开心 。。。O_O。。。这一阵子也看了各种各校的书籍,技术类的、非技术类的,也找到了自身很多的不足之处,我会用更多的心思来弥补不足,希望大家一起努力、加油!
以上是对自己讲的一点废话,现在开始今天的主题,控件渲染Shade(也可以叫着色器,但坏小马不喜欢这么叫,着色器….怪怪的!)的使用,一直都有在关注这方面的东西,网上也有部分文章写得不错,但是还是觉得不过瘾,往往都是写一点点自己在工作中使用过的,有看到过很多人经典问这个边框那个边框的,呵呵,今天小马就总结下这方面的东西,希望对这块知识有兴趣的帅果、美驴们有所帮助或提高,也备自己不时之用,果断先看效果再一步步看代码!希望大家仔细看看我在XML及.java中添加的注释,相信你不会后悔花时间在这文章上的,今天的DEMO效果图如下:
工程目录结构如下,由于太长的原因,部分已缩进:
好了,效果看完了,下一步开始看代码吧,亲…….静下心….一步步来!!!
PS:模拟器与eclipse效果中
预览的以下部分有点不一样,可能是eclipse与模拟器二者之前存在Bug吧…吼吼….
首先,先做个小小的铺垫:
Android提供的Shader类主要是渲染图像以及一些几何图形。
Shader有几个直接子类:
BitmapShader
: 主要用来渲染图像
LinearGradient
:用来进行线性渲染
RadialGradient
: 用来进行环形渲染
SweepGradient
: 扫描渐变—围绕一个中心点扫描渐变就像电影里那种雷达扫描,用来梯度渲染。
ComposeShader
: 组合渲染,可以和其他几个子类组合起来使用。
小记:Android控件渲染Shade的实现方式有两种,(一、JAVA代码实现;二、XML配置来实现),
小马自己比较偏向XML实现,原因很简单:
1.你代码实现写得再经典,不跑起来效果看不到!
2.跑一遍Android模拟器,思路可以断一大节!(我很笨,经常这样 T_T)!
3.JAVA代码的每个函数参数你也得一个个去啃(老板管效率,不管怎么实现,等你啃完参数时,XML已经看到效果了 O_o
起…..)!
4,这是最主要的一点,Eclipse或者I/O大会刚推出的Android Studio,实时显示,我就特别
喜欢立竿见影 ^_^ !
5.二者各有利弊,JAVA代码实现可以动态且灵活滴,XML配置的统一但不杂乱 @_@!!
Ladies and 乡亲们,看举一种JAVA代码excmple,其余类型的与之类似,亲们自己“度娘 、谷哥 ”:
LinearGradient是线性渐变,用法如下:
Gradient是基于Shader类,所以我们通过Paint的setShader方法来设置这个渐变,代码如下:
Paint p=new Paint();
LinearGradient lg=newLinearGradien(0,0,100,100,Color.RED,Color.BLUE,Shader.TileMode.MIRROR);
Gradient是基于Shader类,所以我们通过Paint的setShader方法来设置这个渐变,代码如下:
p.setShader(lg);
canvas.drawCicle(0,0,200,p); //参数3为画圆的半径,类型为float型。
先不说效果了,PS:看着上面的代码,有没有想哭的冲动啊 ? ? ?感觉乱乱的,不知道是什么,然后单词gradient不懂,一查如下(晕),看着挺牛,还是只是个渲染!不管了,继续往下看…
再看XML布局文件代码:
一:主布局文件代码如下(为了方便,布局是直接拖的,大家不用太关注):
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
&RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"&&&&xmlns:tools="http://schemas.android.com/tools"&&&&android:layout_width="match_parent"&&&&android:layout_height="match_parent"&&&&android:background="@drawable/background"&&&&android:paddingBottom="@dimen/activity_vertical_margin"&&&&android:paddingLeft="@dimen/activity_horizontal_margin"&&&&android:paddingRight="@dimen/activity_horizontal_margin"&&&&android:paddingTop="@dimen/activity_vertical_margin"&&&&tools:context=".MainActivity" &&&&&&&com.xiaoma.shadedemo.TextViewBorder&&&&&&&&android:id="@+id/textView1"&&&&&&&&android:layout_width="wrap_content"&&&&&&&&android:layout_height="wrap_content"&&&&&&&&android:layout_alignParentLeft="true"&&&&&&&&android:layout_alignParentTop="true"&&&&&&&&android:layout_marginLeft="22dp"&&&&&&&&android:layout_marginTop="20dp"&&&&&&&&android:text=" JAVA实现带四条边框"&&&&&&&&android:textColor="@android:color/white"&&&&&&&&android:textSize="25sp" /&&&&&&&com.xiaoma.shadedemo.TextViewBorderLeftRight&&&&&&&&android:id="@+id/TextViewBorder01"&&&&&&&&android:layout_width="wrap_content"&&&&&&&&android:layout_height="wrap_content"&&&&&&&&android:textColor="@android:color/white"&&&&&&&&android:layout_alignLeft="@+id/textView1"&&&&&&&&android:layout_below="@+id/textView1"&&&&&&&&android:layout_marginTop="20dp"&&&&&&&&android:text="JAVA实现带左右边框"&&&&&&&&android:textSize="25sp" /&&&&&&&com.xiaoma.shadedemo.TextViewBorderUnder&&&&&&&&android:id="@+id/TextViewBorder02"&&&&&&&&android:layout_width="wrap_content"&&&&&&&&android:layout_height="wrap_content"&&&&&&&&android:layout_alignLeft="@+id/TextViewBorder01"&&&&&&&&android:textColor="@android:color/white"&&&&&&&&android:layout_below="@+id/TextViewBorder01"&&&&&&&&android:layout_marginTop="33dp"&&&&&&&&android:text="JAVA代码实现下边框"&&&&&&&&android:textSize="25sp" /&&&&&&&TextView&&&&&&&&android:id="@+id/TextViewBorderUnder01"&&&&&&&&android:layout_width="wrap_content"&&&&&&&&android:layout_height="wrap_content"&&&&&&&&android:layout_alignLeft="@+id/button1"&&&&&&&&android:layout_below="@+id/TextViewBorder02"&&&&&&&&android:layout_marginTop="20dp"&&&&&&&&android:text="Shape XML实现边框"&&&&&&&&android:background="@drawable/shape_test"&&&&&&&&android:textColor="@android:color/white"&&&&&&&&android:textSize="25sp" /&&&&&&&Button&&&&&&&&android:id="@+id/button1"&&&&&&&&android:layout_width="wrap_content"&&&&&&&&android:layout_height="wrap_content"&&&&&&&&android:layout_alignLeft="@+id/TextViewBorder02"&&&&&&&&android:layout_below="@+id/TextViewBorderUnder01"&&&&&&&&android:layout_marginTop="29dp"&&&&&&&&android:background="@drawable/shape_selector"&&&&&&&&android:text="Selector与Shape混用按钮"&&&&&&&&android:textColor="@android:color/black" /&&&/RelativeLayout&
二:上面布局中使用的自定义控件代码及Shape渲染代码分别如下:
2.1:JAVA实现带四条边框(自定义TextView JAVA代码一)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
package com.xiaoma.shadedemo;&import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.util.AttributeSet;import android.widget.TextView;&public class TextViewBorder extends TextView{&&&&&/**&&&& * 下面两个方法在构造时需注意: 一:如果是XML文件加载的方式使用自定义控件到布局中是用以下方式, 二:如果是用纯代码的方式加载自定义的控制到而已中时用第二种方式&&&& */&&&&&// 方式一:&&&&public TextViewBorder(Context context, AttributeSet attrs)&&&&{&&&&&&&&super(context, attrs);&&&&}&&&&&// 方式二:&&&&/*&&&& * public TextViewBorder(Context context) { // TODO Auto-generated constructor stub super(context); }&&&& */&&&&&/**&&&& * 1. Rect对象 一个区域对象Rect(left, top, right, bottom) , 是一个左闭右开的区域, 即是说使用 Rect.contains(left, top)为true,&&&& * Rect.contains(right, bottom)为false 2. drawLine方法 drawLine(float startX, float startY, float stopX, float stopY,&&&& * Paint paint) 也是一个左闭右开的区间,只会绘制到stopX-1,stopY-1 3. drawRect(Rect r, Paint paint) 当绘制空心矩形时,绘制的是一个左闭右闭的区域&&&& * 验证方法:下面就是可以验证左闭右开的区间方法,现在知道为什么要-1 了&&&& */&&&&&@Override&&&&protected void onDraw(Canvas canvas)&&&&{&&&&&&&&super.onDraw(canvas);&&&&&&&&&Paint paint = new Paint();&&&&&&&&&paint.setAntiAlias(true);&&&&&&&&&paint.setColor(Color.GREEN);&&&&&&&&&canvas.drawLine(0, 0, this.getWidth() - 1, 0, paint);// 绘制上边框&&&&&&&&&canvas.drawLine(0, 0, 0, this.getHeight() - 1, paint); // 绘制左边框&&&&&&&&&canvas.drawLine(this.getWidth() - 1, 0, this.getWidth() - 1, this.getHeight() - 1, paint); // 绘制右边框&&&&&&&&&canvas.drawLine(0, this.getHeight() - 1, this.getWidth() - 1, this.getHeight() - 1, paint);// 绘制下边框&&&&&}&&&&&/*&&&& * 1. Rect对象&&&& * &&&& * 一个区域对象Rect(left, top, right, bottom) , 是一个左闭右开的区域,即是说使用 Rect.contains(left, top)为true, Rect.contains(right,&&&& * bottom)为false&&&& * &&&& * 2.drawLine方法&&&& * &&&& * drawLine(float startX, float startY, float stopX, float stopY, Paint paint) 也是一个左闭右开的区间,只会绘制到stopX-1,stopY-1&&&& * &&&& * 验证方法:&&&& * &&&& * Canvas c = paint.setColor(Color.RED); c.drawLine(x, y, x+c.getWidth()-1, y, paint); c.drawLine(x,&&&& * y+height-1, x+c.getWidth(), y+height-1, paint); paint.setColor(Color.BLUE); c.drawPoint(x+c.getWidth()-1, y,&&&& * paint); 说明drawLine是没有绘制到右边最后一个点的&&&& * &&&& * 3.drawRect(Rect r, Paint paint)&&&& * &&&& * 当绘制空心矩形时,绘制的是一个左闭右闭的区域&&&& * &&&& * 验证方法:&&&& * &&&& * rect.set(x, y, x+width, y+height); paint.setStyle(Style.STROKE); paint.setColor(Color.BLUE); c.drawRect(rect,&&&& * paint); paint.setColor(Color.RED); c.drawLine(x, y, x+width, y, paint); c.drawLine(x, y+height, x+width,&&&& * y+height, paint); c.drawLine(x, y, x, y+height, paint); c.drawLine(x+width, y, x+width, y+height, paint);&&&& * 当绘制实心矩形时,绘制的是一个左闭右开的区域&&&& * &&&& * 验证方法:&&&& * &&&& * rect.set(x, y, x+width, y+height); paint.setColor(Color.RED); c.drawLine(x, y, x+width, y, paint); c.drawLine(x,&&&& * y+height, x+width, y+height, paint); c.drawLine(x, y, x, y+height, paint); c.drawLine(x+width, y, x+width,&&&& * y+height, paint); paint.setStyle(Style.FILL); paint.setColor(Color.BLUE); c.drawRect(rect, paint);&&&& * 这个规则跟j2me也是一样的,在j2me里,drawRect长宽会多画出1px。SDK的说明是:&&&& * &&&& * The resulting rectangle will cover an area (width + 1) pixels wide by (height + 1) pixels tall. If either width&&&& * or height is less than zero, nothing is drawn.&&&& * &&&& * 例如drawRect(10,10,100,1)绘制,结果是一个2px高的矩形,用fillRect(10,10,100,1),结果是一个1px高的矩形&&&& * &&&& * 以上就是对Android绘图的具体介绍。&&&& */&}&/** * 在布局文件中引用 这样引用就行了..吼吼 &com.xiaoma.shadedemo.TextViewBorder android:id="@+id/a02_txtKSSJ" android:textColor="#000000" * android:layout_marginLeft="10dip" android:layout_width="100dip" android:layout_height="wrap_content" /& */
2.2:JAVA实现带左右边框(自定义TextView JAVA代码二)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
package com.xiaoma.shadedemo;&import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.util.AttributeSet;import android.widget.TextView;&public class TextViewBorderLeftRight extends TextView{&&&&&/**&&&& * 下面两个方法在构造时需注意: 一:如果是XML文件加载的方式使用自定义控件到布局中是用以下方式, 二:如果是用纯代码的方式加载自定义的控制到而已中时用第二种方式&&&& */&&&&&// 方式一:&&&&public TextViewBorderLeftRight(Context context, AttributeSet attrs)&&&&{&&&&&&&&super(context, attrs);&&&&}&&&&&// 方式二:&&&&/*&&&& * public TextViewBorder(Context context) { // TODO Auto-generated constructor stub super(context); }&&&& */&&&&&/**&&&& * 1. Rect对象 一个区域对象Rect(left, top, right, bottom) , 是一个左闭右开的区域, 即是说使用 Rect.contains(left, top)为true,&&&& * Rect.contains(right, bottom)为false 2. drawLine方法 drawLine(float startX, float startY, float stopX, float stopY,&&&& * Paint paint) 也是一个左闭右开的区间,只会绘制到stopX-1,stopY-1 3. drawRect(Rect r, Paint paint) 当绘制空心矩形时,绘制的是一个左闭右闭的区域&&&& * 验证方法:下面就是可以验证左闭右开的区间方法,现在知道为什么要-1 了&&&& */&&&&&@Override&&&&protected void onDraw(Canvas canvas)&&&&{&&&&&&&&super.onDraw(canvas);&&&&&&&&&Paint paint = new Paint();&&&&&&&&&paint.setAntiAlias(true);&&&&&&&&&paint.setColor(Color.GREEN);&&&&&&&&&canvas.drawLine(0, 0, 0, getHeight(), paint);&&&&&&&&&// canvas.drawLine(getWidth(), 0, getWidth() - 1, getHeight() - 1, paint);&&&&&&&&canvas.drawLine(this.getWidth() - 1, 0, this.getWidth() - 1, this.getHeight() - 1, paint);&&&&&&&&&// canvas.drawLine(0, 0, 0, this.getHeight() - 1, paint);&&&&&&&&&// canvas.drawLine(this.getWidth() - 1, 0, this.getWidth() - 1, this.getHeight() - 1, paint);&&&&&&&&&// canvas.drawLine(0, this.getHeight() - 1, this.getWidth() - 1, this.getHeight() - 1, paint);&&&&&}&&&&/*&&&& * 1. Rect对象&&&& * &&&& * 一个区域对象Rect(left, top, right, bottom) , 是一个左闭右开的区域,即是说使用 Rect.contains(left, top)为true, Rect.contains(right,&&&& * bottom)为false&&&& * &&&& * 2.drawLine方法&&&& * &&&& * drawLine(float startX, float startY, float stopX, float stopY, Paint paint) 也是一个左闭右开的区间,只会绘制到stopX-1,stopY-1&&&& * &&&& * 验证方法:&&&& * &&&& * Canvas c = paint.setColor(Color.RED); c.drawLine(x, y, x+c.getWidth()-1, y, paint); c.drawLine(x,&&&& * y+height-1, x+c.getWidth(), y+height-1, paint); paint.setColor(Color.BLUE); c.drawPoint(x+c.getWidth()-1, y,&&&& * paint); 说明drawLine是没有绘制到右边最后一个点的&&&& * &&&& * 3.drawRect(Rect r, Paint paint)&&&& * &&&& * 当绘制空心矩形时,绘制的是一个左闭右闭的区域&&&& * &&&& * 验证方法:&&&& * &&&& * rect.set(x, y, x+width, y+height); paint.setStyle(Style.STROKE); paint.setColor(Color.BLUE); c.drawRect(rect,&&&& * paint); paint.setColor(Color.RED); c.drawLine(x, y, x+width, y, paint); c.drawLine(x, y+height, x+width,&&&& * y+height, paint); c.drawLine(x, y, x, y+height, paint); c.drawLine(x+width, y, x+width, y+height, paint);&&&& * 当绘制实心矩形时,绘制的是一个左闭右开的区域&&&& * &&&& * 验证方法:&&&& * &&&& * rect.set(x, y, x+width, y+height); paint.setColor(Color.RED); c.drawLine(x, y, x+width, y, paint); c.drawLine(x,&&&& * y+height, x+width, y+height, paint); c.drawLine(x, y, x, y+height, paint); c.drawLine(x+width, y, x+width,&&&& * y+height, paint); paint.setStyle(Style.FILL); paint.setColor(Color.BLUE); c.drawRect(rect, paint);&&&& * 这个规则跟j2me也是一样的,在j2me里,drawRect长宽会多画出1px。SDK的说明是:&&&& * &&&& * The resulting rectangle will cover an area (width + 1) pixels wide by (height + 1) pixels tall. If either width&&&& * or height is less than zero, nothing is drawn.&&&& * &&&& * 例如drawRect(10,10,100,1)绘制,结果是一个2px高的矩形,用fillRect(10,10,100,1),结果是一个1px高的矩形&&&& * &&&& * 以上就是对Android绘图的具体介绍。&&&& */&}&/** * 在布局文件中引用 这样引用就行了..吼吼 &com.xiaoma.shadedemo.TextViewBorder android:id="@+id/a02_txtKSSJ" android:textColor="#000000" * android:layout_marginLeft="10dip" android:layout_width="100dip" android:layout_height="wrap_content" /& */
2.3:JAVA代码实现下边框(自定义TextView JAVA代码三)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
package com.xiaoma.shadedemo;&import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.util.AttributeSet;import android.widget.TextView;&public class TextViewBorderUnder extends TextView{&&&&&/**&&&& * 下面两个方法在构造时需注意: 一:如果是XML文件加载的方式使用自定义控件到布局中是用以下方式, 二:如果是用纯代码的方式加载自定义的控制到而已中时用第二种方式&&&& */&&&&&// 方式一:&&&&public TextViewBorderUnder(Context context, AttributeSet attrs)&&&&{&&&&&&&&super(context, attrs);&&&&}&&&&&// 方式二:&&&&/*&&&& * public TextViewBorder(Context context) { // TODO Auto-generated constructor stub super(context); }&&&& */&&&&&/**&&&& * 1. Rect对象 一个区域对象Rect(left, top, right, bottom) , 是一个左闭右开的区域, 即是说使用 Rect.contains(left, top)为true,&&&& * Rect.contains(right, bottom)为false 2. drawLine方法 drawLine(float startX, float startY, float stopX, float stopY,&&&& * Paint paint) 也是一个左闭右开的区间,只会绘制到stopX-1,stopY-1 3. drawRect(Rect r, Paint paint) 当绘制空心矩形时,绘制的是一个左闭右闭的区域&&&& * 验证方法:下面就是可以验证左闭右开的区间方法,现在知道为什么要-1 了&&&& */&&&&&@Override&&&&protected void onDraw(Canvas canvas)&&&&{&&&&&&&&super.onDraw(canvas);&&&&&&&&&Paint paint = new Paint();&&&&&&&&&paint.setAntiAlias(true);&&&&&&&&&paint.setColor(Color.GREEN);&&&&&&&&&// canvas.drawLine(0, 0, this.getWidth() - 1, 0, paint);&&&&&&&&&// canvas.drawLine(0, getHeight(), getWidth() - 1, getHeight(), paint);&&&&&&&&&// canvas.drawLine(this.getWidth() - 1, 0, this.getWidth() - 1, this.getHeight() - 1, paint);&&&&&&&&&canvas.drawLine(0, getHeight() - 1, getWidth() - 1, getHeight() - 1, paint);&&&&&}&&&&&/*&&&& * 1. Rect对象&&&& * &&&& * 一个区域对象Rect(left, top, right, bottom) , 是一个左闭右开的区域,即是说使用 Rect.contains(left, top)为true, Rect.contains(right,&&&& * bottom)为false&&&& * &&&& * 2.drawLine方法&&&& * &&&& * drawLine(float startX, float startY, float stopX, float stopY, Paint paint) 也是一个左闭右开的区间,只会绘制到stopX-1,stopY-1&&&& * &&&& * 验证方法:&&&& * &&&& * Canvas c = paint.setColor(Color.RED); c.drawLine(x, y, x+c.getWidth()-1, y, paint); c.drawLine(x,&&&& * y+height-1, x+c.getWidth(), y+height-1, paint); paint.setColor(Color.BLUE); c.drawPoint(x+c.getWidth()-1, y,&&&& * paint); 说明drawLine是没有绘制到右边最后一个点的&&&& * &&&& * 3.drawRect(Rect r, Paint paint)&&&& * &&&& * 当绘制空心矩形时,绘制的是一个左闭右闭的区域&&&& * &&&& * 验证方法:&&&& * &&&& * rect.set(x, y, x+width, y+height); paint.setStyle(Style.STROKE); paint.setColor(Color.BLUE); c.drawRect(rect,&&&& * paint); paint.setColor(Color.RED); c.drawLine(x, y, x+width, y, paint); c.drawLine(x, y+height, x+width,&&&& * y+height, paint); c.drawLine(x, y, x, y+height, paint); c.drawLine(x+width, y, x+width, y+height, paint);&&&& * 当绘制实心矩形时,绘制的是一个左闭右开的区域&&&& * &&&& * 验证方法:&&&& * &&&& * rect.set(x, y, x+width, y+height); paint.setColor(Color.RED); c.drawLine(x, y, x+width, y, paint); c.drawLine(x,&&&& * y+height, x+width, y+height, paint); c.drawLine(x, y, x, y+height, paint); c.drawLine(x+width, y, x+width,&&&& * y+height, paint); paint.setStyle(Style.FILL); paint.setColor(Color.BLUE); c.drawRect(rect, paint);&&&& * 这个规则跟j2me也是一样的,在j2me里,drawRect长宽会多画出1px。SDK的说明是:&&&& * &&&& * The resulting rectangle will cover an area (width + 1) pixels wide by (height + 1) pixels tall. If either width&&&& * or height is less than zero, nothing is drawn.&&&& * &&&& * 例如drawRect(10,10,100,1)绘制,结果是一个2px高的矩形,用fillRect(10,10,100,1),结果是一个1px高的矩形&&&& * &&&& * 以上就是对Android绘图的具体介绍。&&&& */&}&/** * 在布局文件中引用 这样引用就行了..吼吼 &com.xiaoma.shadedemo.TextViewBorder android:id="@+id/a02_txtKSSJ" android:textColor="#000000" * android:layout_marginLeft="10dip" android:layout_width="100dip" android:layout_height="wrap_content" /& */
2.4:Shape XML实现边框(XML代码)
12345678910111213141516171819
&?xml version="1.0" encoding="utf-8"?&&shape xmlns:android="http://schemas.android.com/apk/res/android" &&&&&&&!-- &solid&&android:color="#cceeff"/&&& 直接写这个的话,可以给控制添加一个整体的背景哦 --&&&&&&stroke&&&&&&&&android:width="0.5dp"&&&&&&&&android:color="#22ccff" /&&&&&&&padding&&android:left="5dp" android:top="5dp" android:right="5dp" android:bottom="5dp"/&&&&&&&size&&&&&&&&android:height="0.5dp"&&&&&&&&android:width="5dp" /& &!-- 目前没有什么用,可删除,留在这个地方防止乱猜 --&&&&&&&corners android:radius="10dp" /& &!-- 这个radius里面的值需要个整型,单位用dp,用其它单位亦无影响 --&&&/shape&
2.5:Selector与Shape混用控件效果实现
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
&?xml version="1.0" encoding="utf-8"?&&selector xmlns:android="http://schemas.android.com/apk/res/android"&&&&&&&!-- 今天主要讲的是shape渲染,shape主要类型分四种,效果如下,我们常用rectangle,也就是矩形渲染,其它的都太丑了!! --&&&&&&&item android:state_pressed="true"& &!--按钮按下时的渲染效果 --& &&&&&&&&&shape android:shape="oval"& & &&&&&&&&&&&&&corners android:radius="10dp" /& &!-- 四个角的角度 --&&
&!--gradient就是梯度渲染,简单说就是颜色渐变,type为渐变方式,总共三种 linear sweep&&ridial,常用linear--& &&&&&&&&&&&&&gradient android:endColor="#eebbbb" android:startColor="#9900ee" android:type="linear" /&&
&!-- padding属性是指定内容与控件边距,这个地方小马专门将距左边距设置较大,方便观察 --& &&&&&&&&&&&&&padding android:bottom="5dp" android:left="20dp" android:right="5dp" android:top="5dp" /&& &&&&&&&&&&&&&!-- solid填充整个区域,颜色为FFDDFF,如果使用整个区域填充的话,上面的gradient梯度会失效,即:覆盖 --& &&&&&&&&&&&&&!-- &solid&&android:color="#FFDDFF"/& --&& &&&&&&&&&&&&&!-- stroke为需要填充的边框,指定颜色及边框宽度&&--& &&&&&&&&&&&&&stroke android:width="3dp" android:color="#000000" /& &&&&&&&&&/shape&&
&!-- &clip android:clipOrientation="vertical" android:gravity="right" android:drawable="@drawable/ic_launcher" /& --&&!-- 试了下没用 --&
&!-- &color android:color="#223344"/& --&
&!-- &scale android:scaleWidth="15dp" android:scaleHeight=" 5dp" android:scaleGravity="center" /& --&&&&&& &/item&&&&&&&item& &!-- 默认 --& &&&&&&&&&shape android:shape="rectangle"& & &&&&&&&&&&&&&corners android:radius="10dp" /& &!-- 四个角的角度 --&&
&!--gradient就是梯度渲染,简单说就是颜色渐变,type为渐变方式,总共三种 linear sweep&&ridial,常用linear--&
&!-- 这个地方一定注意,在使用gradient标签中使用android:type的前提是必须android:gradientRadius="20dp"已经设置,否则会报错 --& &&&&&&&&&&&&&gradient android:endColor="#acefda" android:startColor="#0099ff" android:type="linear" /&&
&!-- padding属性是指定内容与控件边距,这个地方小马专门将距左边距设置较大,方便观察 --& &&&&&&&&&&&&&padding android:bottom="5dp" android:left="20dp" android:right="5dp" android:top="5dp" /&& &&&&&&&&&&&&&!-- solid填充整个区域,颜色为FFDDFF,如果使用整个区域填充的话,上面的gradient梯度会失效,即:覆盖 --& &&&&&&&&&&&&&!-- &solid&&android:color="#FFDDFF"/& --&& &&&&&&&&&&&&&!-- stroke为需要填充的边框,指定颜色及边框宽度&&--& &&&&&&&&&&&&&stroke android:width="3dp" android:color="#000000" /& &&&&&&&&&/shape&&&&& &/item&&&/selector&
怎么样?看着JAVA自定义TextView代码是不是觉得特别的繁琐?今天的主题就是来解决这个问题的….…^_^………下面着重来讲一下Selector与Shape混用控件效果Selector实现的细节,(请仔细看下XML里面的注释 O_O)
每个Item过是由Shape来进行渲染生成最终的效果,首先来看根Shape节点的常用属性&shape android:shape=”rectangle”&:
这个shape属性总共分三种 rectangle(矩形)、oval(椭圆) 、line(删除线)、ring(铃,这个存在不知道有什么意义),其效果分别如下:
1.rectangle
其中,gradient标签中的type为渐变方式,总共三种 linear sweep
ridial,常用linear,其效果分别为(注意:ridial试了无任何效果 T_T)
1.linear效果
2.sweep效果
好了,代码及整体效果已经分解完毕了,如果认真从头到尾的看一边的话,肯定有所收获的,对了,以上的Shape渲染写好了,可以在任意控件上使用…不限于TextView,上面的例子只是拿TextView来开刀用的…大家别误会,呵呵….^_^…. ,最后,小马希望在文章中有什么不清楚或不明白或有错误的地方,请大家直接指出…有错必改的….这个源码小马已经上传到最下面附件中,有兴趣或有用的朋友可以直接下载来跑跑改改看,有批评才有进步,希望有什么不好的,直接指出….在此先谢谢大家啦….
官网参考链接如下(只是没效果图,所以大家也懒得去看这个东西)
这段时间也有在关注各种各样的东西,老听人说学这学那的人越来越多什么的,也希望大家不要随便听人家讲,我敢说….安卓虽然在很多人眼里看来简单、烂,但我觉得如果要深入的话,水还是很深的,如果用心,一定可以做的越来越好的,一步一步来,大家一起努力!做安卓的人越来越多,越有竞争!越有动力!!!这样才会进步!哈哈….加油加油加油! O_O
本文固定链接:
转载请注明:
雨松MOMO提醒您:亲,如果您觉得本文不错,快快将这篇文章分享出去吧 。另外请点击网站顶部彩色广告或者捐赠支持本站发展,谢谢!
作者:小马果
【誓言、会老】…【承诺、会变】…【目标、遥远】…【选择、不后悔】…【对自己要狠】…所有动力,源自兴趣,爱编程,更过编程的过程.....
如果您愿意花10块钱请我喝一杯咖啡的话,请用手机扫描二维码即可通过支付宝直接向我捐款哦。
您可能还会对这些文章感兴趣!
Pingback 引用通告:

我要回帖

更多关于 经典小游戏模拟器 的文章

 

随机推荐