代码拉取完成,页面将自动刷新
1、在项目根目录下的build.gradle文件中
allprojects {
repositories {
maven {
url 'https://s01.oss.sonatype.org/content/repositories/releases/'
}
}
}
2.在app模块的build.gradle文件中
dependencies {
implementation('com.gitee.chinasoft_ohos:MaterialScrollBar:1.0.0')
......
}
sdk6,DevEco Studio 2.2 Beta1下项目可直接运行,
如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件,
并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下
1.如何使用 创建一个MateriaScroller对象,并在布局中引用
<com.turingtechnologies.materialscrollbardemo.MateriaScroller
ohos:id="$+id:fast"
ohos:height="match_parent"
ohos:width="match_content"
ohos:align_parent_right="true"
ohos:orientation="vertical"
app:bubbleColor="#ff0099"
app:bubbleTextColor="#e0e0e0"
app:bubbleTextSize="24fp"
app:handleColor="#ff0099"
app:textStyle="bold"
>
</com.turingtechnologies.materialscrollbardemo.MateriaScroller>
2.自定义气泡框,拖拽bar的类Indicator
/**
* 定义滚动条
*/
@Override
public Component provideHandleView(ComponentContainer container) {
handle = new Hand(getContext());
DirectionalLayout.LayoutConfig layoutConfig = new DirectionalLayout.LayoutConfig(60, 300);
handle.setLayoutConfig(layoutConfig);
handle.setMarginLeft(10);
return handle;
}
* 定义气泡框
*/
@Override
public Component provideBubbleView(ComponentContainer container) {
int radius = AttrHelper.vp2px(paddingDefault, getContext());
float[] radii = new float[]{
radius, radius,
radius, radius,
0, 0,
radius, radius
};
ShapeElement shapeElement2 = new ShapeElement(getContext(), ResourceTable.Graphic_materia_default);
shapeElement2.setCornerRadiiArray(radii);
bubble = LayoutScatter.getInstance(getContext())
.parse(ResourceTable.Layout_fastscroll_defalut_bubble, container, false);
bubble.setBackground(shapeElement2);
bubble.setMarginLeft(15);
return bubble;
}
3.MateriaScroller 定义属性
handleColor = AttrValue.get(attrSet, "handleColor", new Color(STYLE_NONE));
handleComColor = AttrValue.get(attrSet, "handlecomColor", new Color(STYLE_NONE));
bubbleColor = AttrValue.get(attrSet, "bubbleColor", new Color(STYLE_NONE));
bubbleTextColor = AttrValue.get(attrSet, "bubbleTextColor", new Color(STYLE_NONE));
bubbleTextSize = AttrValue.getDimension(attrSet, "bubbleTextSize", STYLE_NONE);
textStyle = AttrValue.get(attrSet, "textStyle", "");
处理滑动事件
**
* 获取可滑动的总高度
*
* @return 高度总滑动值
*/
protected int getTotalScrollH() {
return totalScrollH;
}
private void initHandleMovement() {
handle.setTouchEventListener(new TouchEventListener() {
@Override
public boolean onTouchEvent(Component component, TouchEvent event) {
MmiPoint mScreenPosition = event.getPointerScreenPosition(0);
switch (event.getAction()) {
case TouchEvent.PRIMARY_POINT_DOWN:
scrollMax();
if (titleProvider != null) {
viewProvider.onHandleGrabbed();
float offsetY = mScreenPosition.getY() - handle.getLocationOnScreen()[1];
offset = offsetY;
return true;
}
break;
case TouchEvent.POINT_MOVE:
scrollMax();
isChangingPosition = true;
float relativePos = getRelativeTouchPosition(event);
if (relativePos > 1) relativePos = 1;
else if (relativePos < 0) relativePos = 0;
setScrolledPosition(relativePos);
setRecyclerViewPosition(relativePos);
4.滑动工具类ScrollingUtilities 控件在其整个屏幕上的坐标位置
public static float getViewRawY(Component view) {
int[] location = new int[2];
location[0] = 0;
location[1] = ((Component) view.getComponentParent()).getLocationOnScreen()[1];
return location[1];
}
获取最小值
public static float getValueInRange(float min, float max, float value) {
float minimum = Math.max(min, value);
return Math.min(minimum, max);
}
5.属性工具类AttrValue
读取 xml 属性值
public static <T> T get(AttrSet attrSet, String key, T defValue) {
if (!attrSet.getAttr(key).isPresent()) {
return (T) defValue;
}
Attr attr = attrSet.getAttr(key).get();
if (defValue instanceof String) {
return (T) attr.getStringValue();
} else if (defValue instanceof Long) {
return (T) (Long) (attr.getLongValue());
} else if (defValue instanceof Float) {
return (T) (Float) (attr.getFloatValue());
} else if (defValue instanceof Integer) {
return (T) (Integer) (attr.getIntegerValue());
} else if (defValue instanceof Boolean) {
return (T) (Boolean) (attr.getBoolValue());
} else if (defValue instanceof Color) {
return (T) (attr.getColorValue());
} else if (defValue instanceof Element) {
return (T) (attr.getElement());
} else {
return (T) defValue;
}
CodeCheck代码测试无异常
CloudTest代码测试无异常
病毒安全检测通过
当前版本demo功能与原组件基本无差异
Material Scroll Bar:
Copyright 2016-2017 Turing Technologies, an unincorporated orginisation of Wynne Plaga.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
This licensing is applicable to all code offered as part of this
repository, which can be identified by the lisence notice preceding
the content AND/OR by its inclusion in a package starting with "com.
turingtechnologies.materialscrollbar".
RecyclerView-FastScroll:
Copyright (C) 2016 Tim Malseed
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Launcher 3:
Copyright (C) 2010 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型