微信通讯录中的右侧有个字母条,通过它可以快速找到指定联系人,今天我仿照其样子写了一个
字母表控件代码
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import com.example.learn.R;
/**
*
* Description: 仿微信通讯录中的右侧字母表控件
*
* @author danDingCongRong
* @Version 1.0.0
* @Created at 2014-5-31 22:16:15
* @Modified by [作者] on [修改日期]
*/
public class AlphabetView extends View {
// 字母表中的字符
private String alphabet[] = { "@", "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 int defaultColor = Color.RED;
private int selectColor = Color.BLUE;
// 被选中的字符
private int selectedIndex = 0;
// 画笔--用于绘制右侧字母
Paint paint = new Paint();
// 选中的字母被改变监听器
private OnTouchLetterChangedListener changedListener;
// 选中的字母被释放监听器
private OnTouchLetterReleasedListener releasedListener;
public AlphabetView(Context context) {
super(context);
}
public AlphabetView(Context context, AttributeSet attrs) {
super(context, attrs);