没有合适的资源?快使用搜索试试~ 我知道了~
Android verticaseekbar讲解l
需积分: 0 0 下载量 179 浏览量
2014-08-13
14:21:34
上传
评论
收藏 1.36MB PDF 举报
温馨提示
试读
13页
这个是我在网上看到的一个关于Android seekbar的垂直讲解,本人觉得这个挺实用的,所以就赚了,作者说看懂并实践了,就可以转的,所以就转了!
资源推荐
资源详情
资源评论
14-8-13 在android里做一个竖着的seekbar - demon的专栏 - 博客频道 - CSDN.NET
blog.csdn.net/saintswordsman/article/details/5248233 1/13
demon的专栏
分类: android
7月推荐文章汇总 Android 精彩案例 【独具慧眼 推荐有礼】找出您心中的技术大牛 博文大赛获奖名单公布 关注社区微信
得下载分
在android里做一个竖着的seekbar
2010-01-23 12:56 17162人阅读 评论(20) 收藏 举报
android float null notifications permissions user
工作繁忙,总想有机会停下来喘口气,整理一下思路,做一些积累,但是这样的机会很少。要做android的界
面,基础的要求是熟悉那些内置的组件(prebuilt componments),而有时候这些组件是不够用的,这时候我们就
需要自己写一个新的,或者修改内置的。这就要求我们了解更多知识,比如各个View是怎么画出来的,UI上各种事
件是如何分发和处理的等等。这些我都计划写出来和大家分享,网络上中文资料,说得清楚的太少了,就那么几篇
被广泛的转载。今天说一说如何做一个vertical seekbar,竖起来的seekbar。实现它的过程中就会涉及一些View是
如何被画出来的知识。通过本文你可以实现一个verticalseekbar,你也可以学到一些使用seekbar的知识。
我的一个同事很牛,需要自定义的组件时,从framework中抠出来相关(功能相似、在继承关系的hierarchy中地
位相当)的代码(类),在自己的应用程序中做修改,实现自己想要的功能。需要的style、drawable等资源,有些
是在应用程序里用不了的,就也自己做一份。我们公司做整个系统,从硬件到android到android上的应用系统,
framework我们也修改,主要是功能上的增减。在framework里增加一个verticalseekbar我们也能做到,但是这样兼
容性就被破坏了,所以这位仁兄把需要的拿出来在自己的程序中实现。
我做vertical seekbar也采取这个策略,不和大家啰嗦实现过程中太多因果逻辑,我想很多读者读这篇文章就是为
了做出来一个vertical seekbar。为了方便手头没有代码和开发环境的读者,我会贴上framework中的相关代码。
vertical seekbar当然要实现seekbar一样的功能,所以首先seekbar有的vertical seekbar都要有,直接在你的工
程中新建一个类vertical seekbar,从framework中把seekbar的代码复制过来,做一些必要的修改。我们来看看
seekbar做了些什么.
seekbar代码:
[java]
01. /*
02. * Copyright (C) 2006 The Android Open Source Project
03. *
04. * Licensed under the Apache License, Version 2.0 (the "License");
05. * you may not use this file except in compliance with the License.
06. * You may obtain a copy of the License at
07. *
08. * http://www.apache.org/licenses/LICENSE-2.0
09. *
10. * Unless required by applicable law or agreed to in writing, software
11. * distributed under the License is distributed on an "AS IS" BASIS,
12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13. * See the License for the specific language governing permissions and
14. * limitations under the License.
15. */
16. package android.widget;
17. import android.content.Context;
18. import android.util.AttributeSet;
19. /**
20. * A SeekBar is an extension of ProgressBar that adds a draggable thumb. The user can touch
21. * the thumb and drag left or right to set the current progress level or use the arrow keys.
22. * Placing focusable widgets to the left or right of a SeekBar is discouraged.
原创: 3篇 转载: 0篇
译文: 0篇 评论: 94条
(1564)
(65465)
(17143)
(74)
(20)
(0)
个人资料
saintswordsman
访问: 84520次
积分: 336分
排名: 千里之外
文章搜索
文章分类
android (3)
文章存档
2011年05月 (1)
2010年01月 (2)
阅读排行
android进程间通信:使用AIDL
在android里做一个竖着的seekbar
android Java代码的启动
评论排行
android进程间通信:使用AIDL
在android里做一个竖着的seekbar
android Java代码的启动
推荐文章
最新评论
android进程间通信:使用AIDL
yxhyqy3: 好文章
android进程间通信:使用AIDL
目录视图 摘要视图 订阅
登录 | 注册
14-8-13 在android里做一个竖着的seekbar - demon的专栏 - 博客频道 - CSDN.NET
blog.csdn.net/saintswordsman/article/details/5248233 2/13
23. * <p>
24. * Clients of the SeekBar can attach a {@link SeekBar.OnSeekBarChangeListener} to
25. * be notified of the user's actions.
26. *
27. * @attr ref android.R.styleable#SeekBar_thumb
28. */
29. public class SeekBar extends AbsSeekBar {
30. /**
31. * A callback that notifies clients when the progress level has been
32. * changed. This includes changes that were initiated by the user through a
33. * touch gesture or arrow key/trackball as well as changes that were initiated
34. * programmatically.
35. */
36. public interface OnSeekBarChangeListener {
37.
38. /**
39. * Notification that the progress level has changed. Clients can use the fromUser parameter
40. * to distinguish user-
initiated changes from those that occurred programmatically.
41. *
42. * @param seekBar The SeekBar whose progress has changed
43. * @param progress The current progress level. This will be in the range 0..max where max
44. * was set by {@link ProgressBar#setMax(int)}. (The default value for max is 100.)
45. * @param fromUser True if the progress change was initiated by the user.
46. */
47. void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser);
48.
49. /**
50. * Notification that the user has started a touch gesture. Clients may want to use this
51. * to disable advancing the seekbar.
52. * @param seekBar The SeekBar in which the touch gesture began
53. */
54. void onStartTrackingTouch(SeekBar seekBar);
55.
56. /**
57. * Notification that the user has finished a touch gesture. Clients may want to use this
58. * to re-enable advancing the seekbar.
59. * @param seekBar The SeekBar in which the touch gesture began
60. */
61. void onStopTrackingTouch(SeekBar seekBar);
62. }
63. private OnSeekBarChangeListener mOnSeekBarChangeListener;
64.
65. public SeekBar(Context context) {
66. this(context, null);
67. }
68.
69. public SeekBar(Context context, AttributeSet attrs) {
70. this(context, attrs, com.android.internal.R.attr.seekBarStyle);
71. }
72. public SeekBar(Context context, AttributeSet attrs, int defStyle) {
73. super(context, attrs, defStyle);
74. }
75. @Override
76. void onProgressRefresh(float scale, boolean fromUser) {
77. super.onProgressRefresh(scale, fromUser);
78. if (mOnSeekBarChangeListener != null) {
79. mOnSeekBarChangeListener.onProgressChanged(this, getProgress(), fromUser);
80. }
81. }
82. /**
83. * Sets a listener to receive notifications of changes to the SeekBar's progress level. Also
84. * provides notifications of when the user starts and stops a touch gesture within the SeekBar.
85. *
86. * @param l The seek bar notification listener
87. *
88. * @see SeekBar.OnSeekBarChangeListener
89. */
90. public void setOnSeekBarChangeListener(OnSeekBarChangeListener l) {
91. mOnSeekBarChangeListener = l;
92. }
93.
94. @Override
95. void onStartTrackingTouch() {
96. if (mOnSeekBarChangeListener != null) {
97. mOnSeekBarChangeListener.onStartTrackingTouch(this);
98. }
99. }
100.
cdmar79: RemoteCallbackList
请大家慎用,它自己说是线程安
全的,但是,从网上的原码看,
是线程不...
android进程间通信:使用AIDL
windskiper: 对我帮助很大,第一
次能够完整地理解整个流程!但
是有一点疑问在 mAIDLActivity 中
priv...
android进程间通信:使用AIDL
ljz2009y: aidl定义的文件,都需
要在一个包名下面吧?
android进程间通信:使用AIDL
dreamwdy: 不好意思懂了....
android进程间通信:使用AIDL
黄健彬: 看懂了,谢谢
android进程间通信:使用AIDL
Sai_Wei: 不错,很详细
android进程间通信:使用AIDL
lizongmin1981: 写的非常不错
android进程间通信:使用AIDL
mlj1668956679: 顶顶顶顶顶~~~
android进程间通信:使用AIDL
p11234: 难得的好文章 【赞】
14-8-13 在android里做一个竖着的seekbar - demon的专栏 - 博客频道 - CSDN.NET
blog.csdn.net/saintswordsman/article/details/5248233 3/13
101. @Override
102. void onStopTrackingTouch() {
103. if (mOnSeekBarChangeListener != null) {
104. mOnSeekBarChangeListener.onStopTrackingTouch(this);
105. }
106. }
107.
108. }
它定义了一个接口OnSeekBarChangeListener,接口中定义了三个方法:
void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser);
void onStartTrackingTouch(SeekBar seekBar);
void onStopTrackingTouch(SeekBar seekBar);
看名字也知道它们是做什么的,代码也给了注释。那么它们是怎么做到的呢?seekbar中声明了一个该接口的对象
mOnSeekBarChangeListener,方法setOnSeekBarChangeListener()将给它赋值。在你的程序中定义一个对象,
实现OnSeekBarChangeListener,并调用setOnSeekBarChangeListener()把这个对象传给
mOnSeekBarChangeListener。在seekbar中还有几个override的方法:
void onProgressRefresh(float scale, boolean fromUser)
void onStartTrackingTouch()
void onStopTrackingTouch()
这些方法会在发生了相应事件的时候被调用,而它们又相应地去调用mOnSeekBarChangeListener中的方法,于是
你的程序的定义的响应各种事件的方法就被执行了。
但是这些还不够,我们要让seekbar竖起来,要让thumb上下滑动,实现这些特性的代码在什么地方呢?我们顺着
seekbar的继承关系向上找。来看看absseekbar。
absseekbar的代码:
[java]
01. /*
02. * Copyright (C) 2007 The Android Open Source Project
03. *
04. * Licensed under the Apache License, Version 2.0 (the "License");
05. * you may not use this file except in compliance with the License.
06. * You may obtain a copy of the License at
07. *
08. * http://www.apache.org/licenses/LICENSE-2.0
09. *
10. * Unless required by applicable law or agreed to in writing, software
11. * distributed under the License is distributed on an "AS IS" BASIS,
12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13. * See the License for the specific language governing permissions and
14. * limitations under the License.
15. */
16. package android.widget;
17. import android.content.Context;
18. import android.content.res.TypedArray;
19. import android.graphics.Canvas;
20. import android.graphics.Rect;
21. import android.graphics.drawable.Drawable;
22. import android.util.AttributeSet;
23. import android.view.KeyEvent;
24. import android.view.MotionEvent;
25. public abstract class AbsSeekBar extends ProgressBar {
26. private Drawable mThumb;
27. private int mThumbOffset;
28.
29. /**
30. * On touch, this offset plus the scaled value from the position of the
31. * touch will form the progress value. Usually 0.
32. */
33. float mTouchProgressOffset;
34. /**
35. * Whether this is user seekable.
剩余12页未读,继续阅读
资源评论
十二番僧
- 粉丝: 1
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功