设为首页 加入收藏

TOP

Android项目实战(二十三):仿QQ设置App全局字体大小(三)
2017-10-13 10:47:31 】 浏览:7068
Tags:Android 项目 实战 二十三 设置 App 全局 字体 大小
()-1){ 119 canvas.drawBitmap(spot, width - spot_on.getWidth() - bitMapHeight/2, height * 2 / 3 - spot.getHeight() / 2, mPaint); 120 }else { 121 canvas.drawBitmap(spot, thumb.getWidth()/2 + section * perWidth + section * spot_on.getWidth(), height * 2 / 3 - spot.getHeight() / 2, mPaint); 122 } 123 } 124 125 if(section == section_title.size()-1) { 126 canvas.drawText(section_title.get(section), width - spot_on.getWidth()- bitMapHeight/4 - textSize / 2, height * 2 / 3 - textMove, mTextPaint); 127 }else{ 128 canvas.drawText(section_title.get(section), thumb.getWidth()/2 + section * perWidth + section * spot_on.getWidth(), height * 2 / 3 - textMove, mTextPaint); 129 } 130 section++; 131 } 132 if(cur_sections == section_title.size()-1){ 133 canvas.drawBitmap(thumb, width - spot_on.getWidth() - bitMapHeight/2 - thumb.getWidth() / 2, 134 height * 2 / 3 - bitMapHeight, buttonPaint); 135 }else { 136 canvas.drawBitmap(thumb, thumb.getWidth()/2 + cur_sections * perWidth + cur_sections * spot_on.getWidth() - thumb.getWidth()/4 , 137 height * 2 / 3 - bitMapHeight, buttonPaint); 138 } 139 } 140 141 @Override 142 public boolean onTouchEvent(MotionEvent event) { 143 super.onTouchEvent(event); 144 switch (event.getAction()) { 145 case MotionEvent.ACTION_DOWN: 146 thumb = BitmapFactory.decodeResource(getResources(), R.mipmap.img_setting_seekbar_thumbe_large); 147 downX = (int) event.getX(); 148 downY = (int) event.getY(); 149 responseTouch(downX, downY); 150 break; 151 case MotionEvent.ACTION_MOVE: 152 thumb = BitmapFactory.decodeResource(getResources(), R.mipmap.img_setting_seekbar_thumbe_large); 153 moveX = (int) event.getX(); 154 moveY = (int) event.getY(); 155 responseTouch(moveX, moveY); 156 break; 157 case MotionEvent.ACTION_UP: 158 thumb = BitmapFactory.decodeResource(getResources(), R.mipmap.img_setting_seekbar_thumbe_large); 159 upX = (int) event.getX(); 160 upY = (int) event.getY(); 161 responseTouch(upX, upY); 162 responseOnTouch.onTouchResponse(cur_sections); 163 break; 164 } 165 return true; 166 } 167 private void responseTouch(int x, int y){ 168 if(x <= width-bitMapHeight/2) { 169 cur_sections = (x + perWidth / 3) / perWidth; 170 }else{ 171 cur_sections = section_title.size()-1; 172 } 173 invalidate(); 174 } 175 176 //设置监听 177 public void setResponseOnTouch(ResponseOnTouch response){ 178 //注意 ,这里是接口,实现你到达界点的监听事件,因为这个自定义控件继承的View而不是SeekBar,所以只能使用接口实现监听 179 responseOnTouch = response; 180 } 181 182 183 //设置进度 184 public void setProgress(int progress){ 185 cur_sections = progress; 186 invalidate(); 187 } 188 } CustomSeekbar.class

 

2、根据这个自定义CustomSeekbar控件,我们首先要建一个接口

public interface ResponseOnTouch {
    public void onTouchResponse(int volume);
}

 

3、创建一个类。设置一个静态属性 

public class Constant {
public static int TEXT_SIZE = 0;
}

 

4、接下来写字体设置后的效果界面:qq的效果界面有两个,一个是聊天的界面,一个是列表的界面。

这里我们只展示列表的界面

列表代码就不展示了

直接看如何使用CustomSeekbar

 1         private CustomSeekbar seekBar;
 2         seekBar = (CustomSeekbar) findViewById(R.id.progressBar);
 3      //这个集合用于给自定义SeekBar设置界点级别,集合里有几个数据,就有几个界点
 4         ArrayList<String> volume_sections = new ArrayList<String>();      
 5         volume_sections.add("");
 6         volume_sections.add("标准");
 7         volume_sections.add(
首页 上一页 1 2 3 4 下一页 尾页 3/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇对于HDMI设备连接状态的监听 下一篇Android高效计算——RenderScript..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目