全网整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:400-708-3566

Android编程实现文字倒影效果的方法

本文实例讲述了Android编程实现文字倒影效果的方法。分享给大家供大家参考,具体如下:

我们所有的view都继承自View类,View类里有个方法叫ondraw(). 即,我们看到的界面都是画出来的,所以我们可以重写ondraw()方法。

既然知道了这点就好办了,还有个难点就是,我们的倒影也是画出来的,那我们从哪去取原始图片呢?熟悉View的童鞋都知道Cache这个东西,不错,就是通过Cache我们取到了原始图片。

放源码了。,感谢期待。这个只是个demo,并不完善哈,布局什么的还需要调整下,或者我什么时候有空再进行一次封装,就可以直接从布局文件中任意调整了。

布局文件中增加如下代码

<com.tc.reflect.ReflectTextView
    android:layout_marginTop="20dp"
    android:id="@+id/test_reflect" android:layout_width="fill_parent"
    android:layout_height="50dp" android:textSize="25dp"
    android:textColor="#ff0000" android:textStyle="bold" android:gravity="top|center_horizontal"
    android:text="不会飞翔的翅膀 XP.C" />
    <com.tc.reflect.ReflectTextView
    android:layout_marginTop="20dp"
    android:id="@+id/test_reflect" android:layout_width="fill_parent"
    android:layout_height="50dp" android:textSize="25dp"
    android:textColor="#a0a0a0" android:textStyle="italic" android:gravity="top|center_horizontal"
    android:text="titanchen2000@yahoo.com.cn" />

类代码如下:

/*
 * Copyright (C) 2011 TC Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied. See the License for the specific language governing permissions and limitations under the
 * License. This code is base on the Android TextView and was Created by titanchen2000@yahoo.com.cn
 *
 * @author TC
 */
package com.tc.reflect;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuffXfermode;
import android.graphics.PorterDuff.Mode;
import android.graphics.Shader.TileMode;
import android.util.AttributeSet;
import android.widget.TextView;
public class ReflectTextView extends TextView {
  public ReflectTextView(Context context) {
    super(context);
  }
  public ReflectTextView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
  }
  public ReflectTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
  }
  @Override
  protected void onDraw(Canvas canvas) {
    //draw the text from layout()
    super.onDraw(canvas);
    int height = getHeight();
    int width = getWidth();
    //make the shadow reverse of Y
    Matrix matrix = new Matrix();
    matrix.preScale(1, -1);
    //make sure you can use the cache
    setDrawingCacheEnabled(true);
    //create bitmap from cache,this is the most important of this
    Bitmap originalImage = Bitmap.createBitmap(getDrawingCache());
    //create the shadow
    Bitmap reflectionImage = Bitmap.createBitmap(originalImage, 0,
        height / 3, width, height / 3, matrix, false);
    //draw the shadow
    canvas.drawBitmap(reflectionImage, 0, 8 * height / 12, null);
    //process shadow bitmap to make it shadow like
    Paint paint = new Paint();
    LinearGradient shader = new LinearGradient(0, 8 * height / 12, 0,
        height, 0x70ffffff, 0x00ffffff, TileMode.CLAMP);
    paint.setShader(shader);
    paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    canvas.drawRect(0, 8 * height / 12, width, height, paint);
  }
}

更多关于Android相关内容感兴趣的读者可查看本站专题:《Android图形与图像处理技巧总结》、《Android开发入门与进阶教程》、《Android调试技巧与常见问题解决方法汇总》、《Android基本组件用法总结》、《Android视图View技巧总结》、《Android布局layout技巧总结》及《Android控件用法总结》

希望本文所述对大家Android程序设计有所帮助。


# Android  # 文字  # 倒影  # 控制Android LED灯颜色的代码实例  # 详解Android应用层制作LED指示灯  # Android实现文字和图片混排(文字环绕图片)效果  # android显示TextView文字的倒影效果实现代码  # Android实现文字翻转动画的效果  # Android实现文字滚动效果  # Android自定义Dialog实现文字动态加载效果  # Android中使用TextView实现文字跑马灯效果  # Android Shader应用开发之霓虹闪烁文字效果  # Android编程实现类似天气预报图文字幕垂直滚动效果的方法  # Android基于ViewFilpper实现文字LED显示效果示例  # 有个  # 画出  # 都是  # 进阶  # 是个  # 相关内容  # 什么时候  # 就好  # 感兴趣  # 我们可以  # 给大家  # 还需要  # 重写  # 更多关于  # 解决方法  # 办了  # 所述  # 图像处理  # 程序设计  # 就可以 


相关文章: 怎么制作网站设计模板图片,有电商商品详情页面的免费模板素材网站推荐吗?  在线制作视频的网站有哪些,电脑如何制作视频短片?  相亲简历制作网站推荐大全,新相亲大会主持人小萍萍资料?  交易网站制作流程,我想开通一个网站,注册一个交易网址,需要那些手续?  建站之星伪静态规则如何设置?  香港服务器部署网站为何提示未备案?  青岛网站建设如何选择本地服务器?  c++如何打印函数堆栈信息_c++ backtrace函数与符号名解析【方法】  深圳网站制作费用多少钱,读秀,深圳文献港这样的网站很多只提供网上试读,但有些人只要提供试读的文章就能全篇下载,这个是怎么弄的?  ppt制作免费网站有哪些,ppt模板免费下载网站?  jQuery 常见小例汇总  专业企业网站设计制作公司,如何理解商贸企业的统一配送和分销网络建设?  网站广告牌制作方法,街上的广告牌,横幅,用PS还是其他软件做的?  深圳网站制作的公司有哪些,dido官方网站?  建站之星安装需要哪些步骤及注意事项?  如何通过VPS搭建网站快速盈利?  宁波自助建站系统如何快速打造专业企业网站?  平台云上自助建站如何快速打造专业网站?  C++时间戳转换成日期时间的步骤和示例代码  购物网站制作费用多少,开办网上购物网站,需要办理哪些手续?  自助网站制作软件,个人如何自助建网站?  javascript中对象的定义、使用以及对象和原型链操作小结  C#怎么创建控制台应用 C# Console App项目创建方法  高防服务器租用如何选择配置与防御等级?  宝塔面板创建网站无法访问?如何快速排查修复?  北京网站制作公司哪家好一点,北京租房网站有哪些?  网站制作的软件有哪些,制作微信公众号除了秀米还有哪些比较好用的平台?  建站之星备案流程有哪些注意事项?  如何选择域名并搭建高效网站?  网站制作公司,橙子建站是合法的吗?  独立制作一个网站多少钱,建立网站需要花多少钱?  智能起名网站制作软件有哪些,制作logo的软件?  个人摄影网站制作流程,摄影爱好者都去什么网站?  建站三合一如何选?哪家性价比更高?  mc皮肤壁纸制作器,苹果平板怎么设置自己想要的壁纸我的世界?  如何设置并定期更换建站之星安全管理员密码?  已有域名和空间如何搭建网站?  如何续费美橙建站之星域名及服务?  网站图片在线制作软件,怎么在图片上做链接?  整蛊网站制作软件,手机不停的收到各种网站的验证码短信,是手机病毒还是人为恶搞?有这种手机病毒吗?  桂林网站制作公司有哪些,桂林马拉松怎么报名?  盘锦网站制作公司,盘锦大洼有多少5G网站?  网站制作软件免费下载安装,有哪些免费下载的软件网站?  如何通过可视化优化提升建站效果?  制作旅游网站html,怎样注册旅游网站?  详解jQuery中基本的动画方法  建站之星代理费用多少?最新价格详情介绍  如何快速完成中国万网建站详细流程?  如何在Ubuntu系统下快速搭建WordPress个人网站?  韩国代理服务器如何选?解析IP设置技巧与跨境访问优化指南 

您的项目需求

*请认真填写需求信息,我们会在24小时内与您取得联系。