大家晚上好,,小鹿又来了。。最近小鹿特别忙,忙到没时间发表博客了(注:以下内容过于简单请大家不要喷,仅提供初学者学习)

今天发表两篇文章,分别是讲解模拟QQ表情的实现,先给大家看效果图,,,,

开始了,首先我们对QQ表情并不陌生了吧,用它们更不陌生了,每当我们上QQ的时候,总会想发表QQ表情来发泄我们的内心感情....

那么,这么好玩的东西,那我们也应该来玩玩一下怎么实现它们,由上图可知,是完全没有实现出QQ表情的原本效果,但总有点一样,那就不管了,接下来的就靠大家去实现更高级的效果了,小鹿能力有限。

废话不多说了,先说说本内容涉及到的知识点:

①简单的GridView使用

②想不出了....

光说好像大家都不太明白了,那就以代码讲话吧。

以下是MainActivity.java

public class MainActivity extends Activity {private QQFaceAdapter mQQFaceAdapter = null;private GridView mGridView = null;private EditText mEditText = null;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mQQFaceAdapter = new QQFaceAdapter(this);mGridView = (GridView) findViewById(R.id.tweet_detail_foot_faces);mEditText = (EditText) findViewById(R.id.tweet_detail_foot_editer);mGridView.setAdapter(mQQFaceAdapter);mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {public void onItemClick(AdapterView<?> parent, View view,int position, long id) {SpannableString spannableString = new SpannableString(view.getTag().toString());Drawable drawable = getResources().getDrawable((int) mQQFaceAdapter.getItemId(position));drawable.setBounds(0, 0, 35, 35);ImageSpan imageSpan = new ImageSpan(drawable,ImageSpan.ALIGN_BOTTOM);spannableString.setSpan(imageSpan, 0, view.getTag().toString().length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);mEditText.getText().insert(mEditText.getSelectionStart(),spannableString);}});}}

MainActivity.java中

mGridView.setOnItemClickListener

设定当点击哪个图标时,获取图标并把图标放进EditText中

GridView的适配器如下:QQFaceAdapter.java

public class QQFaceAdapter extends BaseAdapter {private Context mContext;private static int[] mImageIds = new int[] { R.drawable.f001,R.drawable.f002, R.drawable.f003, R.drawable.f004, R.drawable.f005,R.drawable.f006, R.drawable.f007, R.drawable.f008, R.drawable.f009,R.drawable.f010, R.drawable.f011, R.drawable.f012, R.drawable.f013,R.drawable.f014, R.drawable.f015, R.drawable.f016, R.drawable.f017,R.drawable.f018, R.drawable.f019, R.drawable.f020, R.drawable.f021,R.drawable.f022, R.drawable.f023, R.drawable.f024, R.drawable.f025,R.drawable.f026, R.drawable.f027, R.drawable.f028, R.drawable.f029,R.drawable.f030, R.drawable.f031, R.drawable.f032, R.drawable.f033,R.drawable.f034, R.drawable.f035, R.drawable.f036, R.drawable.f037,R.drawable.f038, R.drawable.f039, R.drawable.f040, R.drawable.f041,R.drawable.f042, R.drawable.f043, R.drawable.f044, R.drawable.f045,R.drawable.f046, R.drawable.f047, R.drawable.f048, R.drawable.f049,R.drawable.f050, R.drawable.f051, R.drawable.f052, R.drawable.f053,R.drawable.f054, R.drawable.f055, R.drawable.f056, R.drawable.f057,R.drawable.f058, R.drawable.f059, R.drawable.f060, R.drawable.f061,R.drawable.f062, R.drawable.f063, R.drawable.f064, R.drawable.f065,R.drawable.f067, R.drawable.f068, R.drawable.f069, R.drawable.f070,R.drawable.f071, R.drawable.f072, R.drawable.f073, R.drawable.f074,R.drawable.f075, R.drawable.f076, R.drawable.f077, R.drawable.f078,R.drawable.f079, R.drawable.f080, R.drawable.f081, R.drawable.f082,R.drawable.f083, R.drawable.f084, R.drawable.f085, R.drawable.f086,R.drawable.f087, R.drawable.f088, R.drawable.f089, R.drawable.f090,R.drawable.f091, R.drawable.f092, R.drawable.f093, R.drawable.f094,R.drawable.f095, R.drawable.f096, R.drawable.f097, R.drawable.f098,R.drawable.f099, R.drawable.f100, R.drawable.f101, R.drawable.f103,R.drawable.f104, R.drawable.f105 };public QQFaceAdapter(Context c) {mContext = c;}// 获取图片的总idpublic static int[] getImageIds() {return mImageIds;}// 获取图片的个数public int getCount() {return mImageIds.length;}// 获取图片在库中的位置public Object getItem(int position) {return position;}// 获取图片IDpublic long getItemId(int position) {return mImageIds[position];}public View getView(int position, View convertView, ViewGroup parent) {ImageView imageView;if (convertView == null) {imageView = new ImageView(mContext);imageView.setLayoutParams(new GridView.LayoutParams(85, 85));imageView.setScaleType(ImageView.ScaleType.CENTER);} else {imageView = (ImageView) convertView;}imageView.setImageResource(mImageIds[position]);if (position < 65) {imageView.setTag("[" + position + "]");} else if (position < 100) {imageView.setTag("[" + (position + 1) + "]");} else {imageView.setTag("[" + (position + 2) + "]");}return imageView;}
}

activity_main.xml的代码如下:

<LinearLayout 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:orientation="vertical" ><GridViewandroid:id="@+id/tweet_detail_foot_faces"android:layout_width="fill_parent"android:layout_height="220dip"android:background="@color/face_bg"android:columnWidth="50dip"android:fadingEdge="none"android:gravity="center"android:numColumns="auto_fit"android:scrollingCache="false"android:stretchMode="columnWidth" /><EditTextandroid:id="@+id/tweet_detail_foot_editer"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_marginBottom="5dip"android:layout_marginTop="5dip"android:autoLink="web|email"android:focusable="true"android:focusableInTouchMode="true"android:gravity="top"/></LinearLayout>

代码已经贴完了,如果大家喜欢,就请大家新建一个项目,再把代码贴到项目中,图片资源稍后上传更新请大家多多关注(最近在博客中上传不了资源,小鹿也不懂怎么回事,请大家多多原谅,,,)

最后结束语:以上代码看不懂的朋友请留个言,小鹿会很关照滴,如果觉得本次内容不好请不要喷,给点评论我会好好改进,在此多谢大家了。

--------------------------------------------------------------------------------------------

源码地址:http://download.csdn.net/detail/lusiting/8098163

--------------------------------------------------------------------------------------------

下集预告:Android开发之仿QQ表情实现(下)

Android开发之仿QQ表情实现(上)相关推荐

  1. Android开发之仿QQ表情实现(下)

    大家中午好,,,,,,小鹿吃草刚回来真是不好意思,,,, 上篇文章已经讲到GirdView的使用,本节内容是基于上篇内容实现更完美的QQ表情的实现,具体的说,本节内容实现的QQ表情是使用了GirdVi ...

  2. android开发之仿QQ拖拽界面效果(侧滑面板)

    仿QQ拖拽界面效果(侧滑面板),我们一般继承Layout,不会直接去继承ViewGroup,而是继承FrameLayout,为什么五大布局我们偏偏只继承FrameLayout呢? 第一,FrameLa ...

  3. Android开发之仿360手机卫士悬浮窗效果

    基本的实现原理,这种桌面悬浮窗的效果很类似与Widget,但是它比Widget要灵活的多.主要是通过WindowManager这个类来实现的,调用这个类的addView方法用于添加一个悬浮窗,upda ...

  4. 安卓开发之仿QQ界面

    安卓开发之仿腾讯QQ 1.系统功能说明及软件界面展示 2.软件界面展示 3.数据流图(我瞎画的) 4.操作流程图(也是我瞎画的) 1.系统功能说明及软件界面展示 此APP是模仿的移动端的腾讯QQ.众所 ...

  5. Android开发之QQ空间效果(QQ空间下拉图片放大,松手后回弹)

    Android开发之QQ空间效果(QQ空间下拉图片放大,松手后回弹) 腾讯QQ空间的下拉图片放大,松手后回弹的效果带来的视觉差异效果让许多移动开发者心动不已,经本人一段时间的研究,终于实现了该视差效果 ...

  6. Android开发之无bug滑动删除源码(非第三方库)

    Android开发之无bug滑动删除源码(非第三方库源码请在最后面自行下载) 1.我们先来看下效果图:上边是抽取出来的demo,下边是公司用到的项目 2.我们来看下如何调用(我们这里以listView ...

  7. Android 开发之Okhttp网络请求日志打印

    这里写自定义目录标题 Android 开发之Okhttp 网络请求日志打印 OkHTTP网络日志打印 Android 开发之Okhttp 网络请求日志打印 网络请求是开发的日常工作内容之一,网络日志打 ...

  8. android开发之Intent.setFlags()_让Android点击通知栏信息后返回正在运行的程序

    android开发之Intent.setFlags()_让Android点击通知栏信息后返回正在运行的程序   在应用里使用了后台服务,并且在通知栏推送了消息,希望点击这个消息回到activity, ...

  9. Android开发之TextView高级应用

    Android开发之TextView高级应用 我们平时使用TextView往往让它作为一个显示文字的容器,但TextView的功能并不局限于此.以下就和大家分享一下TextView的一些使用技巧. A ...

最新文章

  1. ip别名删除第一个,其余别名就自动删除的分析
  2. 2021年春季学期-信号与系统-第十次作业参考答案-第三小题
  3. 05构建之法阅读笔记之三
  4. System.Threading.Timer 定时器的用法
  5. 苹果官网再度开售iPhone SE:这是在为新品清库存了?
  6. 监控、链路追踪、日志的区别
  7. Spring学习总结(10)——Spring JMS---三种消息监听器
  8. 计算机信息技术教程(笔记)
  9. 35KV,110KV变电所设计,供配电电气部分设计
  10. Aop切面自定义注解的使用
  11. 计算机网络体系结构中协议和服务的差别,第3章 计算机网络体系结构及协议 -4-2...
  12. 做到30条业绩翻十倍
  13. Word表格中的孤行控制?
  14. 盛世昊通以汽车生态链为流量入口,布局九大生态板块
  15. Ubuntu 安装k8s集群
  16. 748. 数组的右下半部分
  17. leetcode day1
  18. 读书笔记 effective c++ Item 30 理解内联的里里外外 (大师入场啦)
  19. 安装环境Anaconda+pytorch
  20. 【uiautomation】微信好友列表获取(存储到txt中)

热门文章

  1. an unsupported operation was attempted错误
  2. 2019,被催更了!2020,干就是了!
  3. APK汉化手记 现金流游戏放出
  4. 使用OD加载微软符号库
  5. sql优化的15个小技巧(必知五颗星),面试说出七八个就有了
  6. Python主要用来做什么?
  7. Windows无限弹窗程序
  8. 一个项目经理能同时管几个项目?
  9. CI information
  10. [转]敏感信息识别方法探究