示例 Swipe of Swing
示例 Swipe of Both Sides
示例 Drag Right Side Swipe
示例 Two-steps Right Swipe
1.在项目根目录下的build.gradle文件中,
allprojects {
repositories {
maven {
url 'https://s01.oss.sonatype.org/content/repositories/releases/'
}
}
}
2.在entry模块的build.gradle文件中,
dependencies {
implementation('com.gitee.chinasoft_ohos:swipemaker:1.0.0')
......
}
在sdk6,DevEco Studio 2.2 Beta1下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下
让我们一起实现一个 Right Side Swipe
1.继承AbsCoordinatorLayout并创建自己的Provider,在本例中,我称之为halfrightcordinatorlayout
public class HalfRightCoordinatorLayout extends AbsCoordinatorLayout {
新增一个 init() 方法。并在自己创建的Provider中调用。为滑动小部件设置锚定。定位点是滑动卡片之间的边界。我们希望在按钮“mBackgroundView”边界内滑动
public void init() {
mForegroundView = (SwipeLayout)findComponentById(ResourceTable.Id_foregroundView);
mBackgroundView = findComponentById(ResourceTable.Id_backgroundView);
mForegroundView.setOnTranslateChangeListener(this);
sync(mForegroundView);
this.addDrawTask(new DrawTask() {
@Override
public void onDraw(Component component, Canvas canvas) {
mForegroundView.anchor(mBackgroundView.getRight(), mBackgroundView.getLeft());
}
});
}
2.需要注意的是,布局文件中: SwipeLayout Id 必须是 $+id:foregroundView
backgroundView Id必须是 $+id:foregroundView
<?xml version="1.0" encoding="utf-8"?>
<apps.xenione.com.swipelayout.example.swipe.HalfRightCoordinatorLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:width="match_parent"
ohos:height="250vp">
<DirectionalLayout
ohos:id="$+id:backgroundView"
ohos:height="match_parent"
ohos:width="match_content"
ohos:background_element="#FF4081"
ohos:alignment="center">
<Image
ohos:width="match_content"
ohos:height="match_content"
ohos:padding="13vp"
ohos:image_src="$graphic:ic_delete" />
</DirectionalLayout>
<com.xenione.libs.swipemaker.SwipeLayout
ohos:id="$+id:foregroundView"
ohos:width="match_parent"
ohos:height="250vp"
ohos:orientation="vertical">
<Image
ohos:id="$+id:bg_disc"
ohos:width="match_parent"
ohos:height="250vp"
ohos:scale_mode="clip_center"
/>
<DependentLayout
ohos:width="match_parent"
ohos:height="match_parent">
<Text
ohos:id="$+id:bandName"
ohos:width="match_content"
ohos:height="match_content"
ohos:text_color="#FFFFFF"
ohos:background_element="#000000"
ohos:alpha="0.80"
ohos:padding="13vp"
ohos:text_size="14fp"
ohos:align_parent_right="true"
ohos:align_parent_end="true"
ohos:align_parent_top="true"
ohos:top_margin="30vp"
ohos:end_margin="30vp"
ohos:right_margin="30vp"
/>
<Text
ohos:id="$+id:title"
ohos:width="match_content"
ohos:text_color="#FFFFFF"
ohos:background_element="#FF4081"
ohos:alpha="0.80"
ohos:padding="13vp"
ohos:text_size="15fp"
ohos:height="match_content"
ohos:align_end="$id:bandName"
ohos:align_right="$id:bandName"
ohos:below="$id:bandName"
/>
</DependentLayout>
</com.xenione.libs.swipemaker.SwipeLayout>
</apps.xenione.com.swipelayout.example.swipe.HalfRightCoordinatorLayout>
3.下面回到AbstracoordinatorLayout继承的类(就是我们的例子HalfRightCoordinatorLayout),您就有了一个名为onTranslateChange(…)的回调。
@Override
public void onTranslateChange(float global, int index, float relative) {
}
您可以在其中监视刷卡进度。
参数说明如下:
global:给我们百分比(1%:0-1):0表示左极限,1表示右极限。
index和relative:如果我们有一个以上的部分,如果我们给出了2个以上的锚点(例如两步滑动),就会发生这种情况
index:是截面的索引(如果我们有3个锚点,我们将有2个截面:一个从锚点1到2,另一个从锚点2到3)
relative:给出index部分中的precentage(1%:0-1)。
在我们的情况下,我们只有一个部分,所以我们不必照顾。所以让我们添加一个很好的过渡效果:
@Override
public void onTranslateChange(float global, int index, float relative) {
mBackgroundView.setAlpha(global);
}
CodeCheck代码测试无异常
CloudTest代码测试无异常
病毒安全检测通过
当前版本demo功能与原组件基本无差异
Copyright 2016 Eugeni Josep Senent i Gabriel
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. 评估模型