android仿iPhone滚轮控件实现及源码分析二Word文档格式.docx
- 文档编号:19474348
- 上传时间:2023-01-06
- 格式:DOCX
- 页数:49
- 大小:33.87KB
android仿iPhone滚轮控件实现及源码分析二Word文档格式.docx
《android仿iPhone滚轮控件实现及源码分析二Word文档格式.docx》由会员分享,可在线阅读,更多相关《android仿iPhone滚轮控件实现及源码分析二Word文档格式.docx(49页珍藏版)》请在冰豆网上搜索。
0)
13.
float
textWidth
FloatMath.ceil(Layout.getDesiredWidth("
0"
itemsPaint));
14.
itemsWidth
(int)
textWidth);
15.
}
else
16.
0;
17.
18.
+=
ADDITIONAL_ITEMS_SPACE;
//
make
it
some
more
19.
20.
labelWidth
21.
(label
!
null
&
label.length()
22.
FloatMath.ceil(Layout.getDesiredWidth(label,
valuePaint));
23.
24.
25.
boolean
recalculate
false;
26.
(mode
==
MeasureSpec.EXACTLY)
27.
28.
true;
29.
30.
+
2
PADDING;
31.
(labelWidth
32.
LABEL_OFFSET;
33.
34.
35.
Check
against
our
minimum
width
36.
Math.max(width,
getSuggestedMinimumWidth());
37.
38.
MeasureSpec.AT_MOST
<
width)
39.
40.
41.
42.
43.
44.
(recalculate)
45.
46.
pureWidth
-
LABEL_OFFSET
47.
(pureWidth
48.
49.
50.
51.
double
newWidthItems
(double)
52.
/
(itemsWidth
labelWidth);
53.
newWidthItems;
54.
itemsWidth;
55.
56.
no
label
57.
58.
59.
60.
61.
createLayouts(itemsWidth,
62.
63.
64.
return
width;
65.
66.
67.
/**
68.
Creates
69.
widthItems
of
items
70.
widthLabel
label
71.
72.
void
createLayouts(int
widthItems,
widthLabel)
73.
(itemsLayout
||
itemsLayout.getWidth()
widthItems)
74.
itemsLayout
new
StaticLayout(buildText(isScrollingPerformed),
itemsPaint,
75.
0
?
Layout.Alignment.ALIGN_OPPOSITE
:
Layout.Alignment.ALIGN_CENTER,
76.
1,
ADDITIONAL_ITEM_HEIGHT,
false);
77.
78.
itemsLayout.increaseWidthTo(widthItems);
79.
80.
81.
(!
isScrollingPerformed
(valueLayout
valueLayout.getWidth()
widthItems))
82.
String
getAdapter()
getAdapter().getItem(currentItem)
null;
83.
valueLayout
StaticLayout(text
"
84.
valuePaint,
85.
86.
87.
(isScrollingPerformed)
88.
89.
90.
valueLayout.increaseWidthTo(widthItems);
91.
92.
93.
(widthLabel
94.
(labelLayout
labelLayout.getWidth()
95.
labelLayout
StaticLayout(label,
96.
widthLabel,
Layout.Alignment.ALIGN_NORMAL,
97.
98.
99.
labelLayout.increaseWidthTo(widthLabel);
100.
101.
102.
103.
104.
@Override
105.
protected
onMeasure(int
widthMeasureSpec,
heightMeasureSpec)
106.
widthMode
MeasureSpec.getMode(widthMeasureSpec);
107.
heightMode
MeasureSpec.getMode(heightMeasureSpec);
108.
MeasureSpec.getSize(widthMeasureSpec);
109.
heightSize
MeasureSpec.getSize(heightMeasureSpec);
110.
111.
calculateLayoutWidth(widthSize,
widthMode);
112.
113.
height;
114.
(heightMode
115.
height
heightSize;
116.
117.
getDesiredHeight(itemsLayout);
118.
119.
MeasureSpec.AT_MOST)
120.
Math.min(height,
heightSize);
121.
122.
123.
124.
setMeasuredDimension(width,
height);
125.
126.
127.
128.
onDraw(Canvas
canvas)
129.
super.onDraw(canvas);
130.
131.
null)
132.
133.
calculateLayoutWidth(getWidth(),
MeasureSpec.EXACTLY);
134.
135.
136.
137.
138.
139.
140.
canvas.save();
141.
Skip
padding
space
hide
a
part
top
bottom
items
142.
canvas.translate(PADDING,
-ITEM_OFFSET);
143.
drawItems(canvas);
144.
drawValue(canvas);
145.
canvas.restore();
146.
147.
148.
drawCenterRect(canvas);
149.
drawShadows(canvas);
150.
151.
152.
153.
Draws
shadows
on
154.
canvas
for
drawing
155.
156.
drawShadows(Canvas
157.
topShadow.setBounds(0,
0,
getWidth(),
getHeight()
visibleItems);
158.
topShadow.draw(canvas);
159.
160.
bottomShadow.setBounds(0,
visibleItems,
161.
getHeight());
162.
bottomShadow.draw(canvas);
163.
164.
165.
166.
value
167.
168.
169.
drawValue(Canvas
170.
valuePaint.setColor(VALUE_TEXT_COLOR);
171.
valuePaint.drawableState
getDrawableState();
172.
173.
Rect
bounds
Rect();
174.
itemsLayout.getLineBounds(visibleItems
2,
bounds);
175.
176.
draw
177.
178.
179.
canvas.translate(itemsLayout.getWidth()
LABEL_OFFSET,
bounds.top);
180.
labelLayout.draw(canvas);
181.
182.
183.
184.
current
value
185.
186.
187.
canvas.translate(0,
bounds.top
scrollingOffset);
188.
valueLayout.draw(canvas);
189.
190.
191.
192.
193.
194.
195.
196.
197.
drawItems(Canvas
198.
199.
200.
itemsLayout.getLineTop
(1);
201.
202.
203.
itemsPaint.setColor(ITEMS_TEXT_COLOR);
204.
itemsPaint.drawableState
205.
itemsLayout.draw(canvas);
206.
207.
208.
209.
210.
211.
rect
212.
213.
214.
drawCenterRect(Canvas
215.
center
2;
216.
offset
getItemHeight()
217.
centerDrawable.setBounds(0,
offset,
offset);
218.
centerDrawable.draw(canvas);
219.
220.
221.
222.
public
onTouchEvent(MotionEvent
event)
223.
WheelAdapter
adapter
getAdapter();
224.
(adapter
225.
226.
227.
228.
gestureDetector.onTouchEvent(event)
event.getAction()
MotionEvent.ACTION_UP)
229.
justify();
230.
231.
232.
233.
234.
235.
Scrolls
wheel
236.
delta
scrolling
237.
238.
doScroll(int
delta)
239.
scrollingOffset
delta;
240.
241.
count
getItemHeight();
242.
pos
currentItem
count;
243.
(isCyclic
adapter.g
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- android iPhone 滚轮 控件 实现 源码 分析