android仿微信点击好友,安卓仿微信联系人快速索引

importandroid.content.Context;importandroid.graphics.Canvas;importandroid.graphics.Paint;importandroid.support.annotation.Nullable;importandroid.util.AttributeSet;importandroid.view.MotionEvent;importandroid.view.View;importcom.example.z.xxxx.R;/*** Created by z on 2017/9/21.*/

public class SlideBar extendsView {private static final String[] BAR_LETTERS = {"A", "B", "C", "D", "E", "F", "G","H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T","U", "V", "W", "X", "Y", "Z", "#"};private Paint paint = newPaint();private int selectIndex = -1;//选项的数组下标

privateonTouchLetterListener onTouchLetterListener;private boolean isShowBkg = false;//背景是否变化

publicSlideBar(Context context) {super(context);

}publicSlideBar(Context context, @Nullable AttributeSet attrs) {super(context, attrs);

}public SlideBar(Context context, @Nullable AttributeSet attrs, intdefStyleAttr) {super(context, attrs, defStyleAttr);

}public interfaceonTouchLetterListener {void onTouchLetterChange(String letter,booleantouch);

}public voidsetOnTouchLetterListener(onTouchLetterListener onTouchLetterListener) {this.onTouchLetterListener =onTouchLetterListener;

}

@Overrideprotected voidonDraw(Canvas canvas) {super.onDraw(canvas);if (isShowBkg == true) {

canvas.drawColor(getResources().getColor(R.color.text_backgroud_color));//显示背景

}int height =getHeight();int width =getWidth();int singleHeight = (height - 20) / BAR_LETTERS.length;//每个字母占得高度

System.out.println(height + "-------" +width);for (int i = 0; i < BAR_LETTERS.length; i++) {//遍历字母

paint.setColor(getResources().getColor(R.color.text_color));

paint.setTextSize(50);

paint.setAntiAlias(true);//设置抗锯齿样式

System.out.println(i+"-----"+selectIndex);if (i == selectIndex) {//如果被选中

System.out.println(i+"*****"+selectIndex);

paint.setColor(getResources().getColor(R.color.isread_true));

paint.setFakeBoldText(true);//加粗

}//从左下角开始绘制

float xpos = (width - paint.measureText(BAR_LETTERS[i])) / 2;//x轴

float ypos = singleHeight * i + singleHeight;//y轴 (i从0开始算)//System.out.println(xpos + "" + ypos);

canvas.drawText(BAR_LETTERS[i], xpos, ypos, paint);//开始绘制

paint.reset();//重置画笔

}

}

@Overridepublic booleandispatchTouchEvent(MotionEvent event) {int action =event.getAction();float ypos =event.getY();int oldSelectIndex = selectIndex;//上一次触发的坐标

int newSelectIndex = (int) (ypos / getHeight() * BAR_LETTERS.length);//根据触摸的位置确定点的哪个字母

switch(action) {caseMotionEvent.ACTION_DOWN:

isShowBkg= true;if (onTouchLetterListener != null && oldSelectIndex !=newSelectIndex&& newSelectIndex >= 0 && newSelectIndex <=BAR_LETTERS.length) {

onTouchLetterListener.onTouchLetterChange(BAR_LETTERS[newSelectIndex],true);//注册点击事件并传入字母

oldSelectIndex =newSelectIndex;

selectIndex=newSelectIndex;

invalidate();//重新绘制

}break;caseMotionEvent.ACTION_UP:

isShowBkg= false;

selectIndex= -1;

invalidate();

onTouchLetterListener.onTouchLetterChange(BAR_LETTERS[newSelectIndex],false);//注册点击事件并传入字母

break;caseMotionEvent.ACTION_MOVE:if (onTouchLetterListener != null && oldSelectIndex !=newSelectIndex&& newSelectIndex >= 0 && newSelectIndex <=BAR_LETTERS.length) {

onTouchLetterListener.onTouchLetterChange(BAR_LETTERS[newSelectIndex],true);//注册点击事件并传入字母

oldSelectIndex =newSelectIndex;

selectIndex=newSelectIndex;

invalidate();//重新绘制

}break;

}return true;

}

@Overridepublic booleanonTouchEvent(MotionEvent event) {return super.onTouchEvent(event);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android仿微信源码是一种模仿微信功能和界面的Android应用程序源代码。通过使用这个源码,开发者可以基于微信的特性和设计思路,快速构建出一个类似微信的应用程序。 Android仿微信源码一般会包含以下几个主要功能和模块: 1. 登录和注册功能:用户可以通过手机号码或者邮箱注册和登录账号。 2. 消息功能:包括文本消息、语音消息、图片消息、表情消息以及文件消息。用户可以发送和接收消息,并且支持定位信息的发送。 3. 朋友圈功能:允许用户发表和查看好友的动态,可以发布文字、图片和视频等内容,并且支持点赞和评论。 4. 通讯录功能:显示用户的好友列表,可以查找新的好友并添加。 5. 个人信息功能:用户可以编辑和查看自己的个人信息,包括昵称、头像、性别、个性签名等。 6. 设置功能:用户可以修改密码、绑定手机号码、更改系统设置等。 7. 实时聊天功能:支持好友之间的实时聊天,并且可以发送语音和图片消息。 8. 推送通知功能:当有新消息或者好友发表动态时,可以通过推送通知提醒用户。 除了以上功能之外,还可以根据需求添加其他功能模块,比如群聊、支付、音视频通话等。 通过使用Android仿微信源码,开发者可以快速搭建起一个类似微信的社交应用,节约开发时间和成本。但是需要注意的是,为了避免侵权问题,开发者在使用仿微信源码时需谨慎,并且遵守相关法律法规。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值