CoolViewPager是一个自定义 ViewPager,具有以下功能特征:
在你的 build.gradle 中添加依赖
dependencies {
implementation 'com.huanhailiuxin.view:coolviewpager:1.0.0'
}
在你的布局文件中引入 CoolViewPager
<com.huanhailiuxin.coolviewpager.CoolViewPager
android:id="@+id/vp"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
在 Java 代码中获取 CoolViewPager,设置各种属性,为其设置 Adapter
public class ActivityEdgeEffectColor extends BaseActivity {
private CoolViewPager vp;
****
CoolViewPager vp = findViewById(R.id.vp);
vp.setScrollMode(CoolViewPager.ScrollMode.HORIZONTAL);
vp.setAdapter(adapter);
****
}
CoolViewPager 具有以下自定义属性,我们可以在 xml 布局文件或通过 Java 代码进行设置:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="CoolViewPager">
<attr name="cvp_scrollmode" format="enum">
<enum name="horizontal" value="0" />
<enum name="vertical" value="1" />
</attr>
<attr name="cvp_autoscroll" format="boolean" />
<attr name="cvp_intervalinmillis" format="integer"/>
<attr name="cvp_autoscrolldirection" format="enum">
<enum name="forward" value="0" />
<enum name="backward" value="1" />
</attr>
<attr name="cvp_infiniteloop" format="boolean" />
<attr name="cvp_scrollduration" format="integer"/>
<attr name="cvp_drawedgeeffect" format="boolean"/>
<attr name="cvp_edgeeffectcolor" format="color"/>
</declare-styleable>
</resources>
<com.huanhailiuxin.coolviewpager.CoolViewPager
android:id="@+id/vp"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:cvp_scrollmode="vertical"
app:cvp_autoscroll="true"
app:cvp_intervalinmillis="1000"
app:cvp_autoscrolldirection="backward"
app:cvp_infiniteloop="true"
app:cvp_scrollduration="600"
app:cvp_drawedgeeffect="true"
app:cvp_edgeeffectcolor="@color/colorPrimary"
/>
public class ActivityEdgeEffectColor extends BaseActivity {
private CoolViewPager vp;
private void initViewPager(){
vp = findViewById(R.id.vp);
vp.setScrollMode(CoolViewPager.ScrollMode.VERTICAL);
vp.setAutoScroll(true,1000);
vp.setAutoScrollDirection(CoolViewPager.AutoScrollDirection.BACKWARD);
vp.setInfiniteLoop(true);
vp.setScrollDuration(true,600);
vp.setDrawEdgeEffect(true);
vp.setEdgeEffectColor(getResources().getColor(R.color.colorPrimary));
}
}
Copyright 2018 HuanHaiLiuXin
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.
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.