是否有默认的DotsPageIndicator for Android mobile(不穿)?

是否有默认的DotsPageIndicator for Android mobile(不穿)?,第1张

概述我想为我的ViewPager使用ViewPageIndicator.我找到了 this DotsPageIndicator,但它似乎只适用于AndroidWear.有趣的是,在每个Android 6设备的主页上都有完全相同的东西,如下图所示(点击查看大图). 那么,是否有一些我只是遗漏的东西,它可以像所有默认的Android内容一样简单实现吗?或者我还需要使用外部库吗?如果后者是真的,我该怎么做? 我想为我的VIEwPager使用VIEwPageIndicator.我找到了 this DotsPageIndicator,但它似乎只适用于AndroIDWear.有趣的是,在每个AndroID 6设备的主页上都有完全相同的东西,如下图所示(点击查看大图).

那么,是否有一些我只是遗漏的东西,它可以像所有默认的AndroID内容一样简单实现吗?或者我还需要使用外部库吗?如果后者是真的,我该怎么做?

解决方法 我很久以前就已经找到了这个问题的答案,但是忘记了我仍然打开了这个问题,所以我现在要尝试回答它,我记得从那时起.所以要注意,它可能并不完美,但我会努力使它尽可能好.

您将需要vIEwPagerIndicator库.我相信这样做的方法是打开build.gradle(Module:app)Gradle脚本,然后转到依赖项并添加编译’com.vIEwpagerindicator:library:2.4.1@aar’

结果应如下所示:

...dependencIEs {    compile filetree(dir: 'libs',include: ['*.jar'])    testCompile 'junit:junit:4.12'    compile "com.androID.support:support-v13:24.1.1"    compile 'com.androID.support:appcompat-v7:24.1.1'    compile 'com.androID.support:support-v4:24.1.1'    compile 'com.androID.support:design:24.1.1'    compile 'com.Google.androID.gms:play-services-appindexing:9.4.0'    compile 'com.vIEwpagerindicator:library:2.4.1@aar'}

接下来,您需要将您喜欢的PageIndicator(我选择Circle版本)添加到您的XML中.这应该与您希望拥有这些指标的VIEwPager位于同一XML文件中.我的文件看起来像这样:

<?xml version="1.0" enCoding="utf-8"?><linearLayout    xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:app="http://schemas.androID.com/apk/res-auto"    androID:orIEntation="vertical"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:layout_centerHorizontal="true">    <com.example.tim.timapp.CustomStuff.Misc.CustomVIEwPager        androID:ID="@+ID/pager"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        androID:overScrollMode="never"/>    <!-- Note that I use a custom VIEwPager for app-specific reasons. -->    <!-- It doesn't matter if you use a custom or default VP as far as I kNow. -->    <com.vIEwpagerindicator.CirclePageIndicator        androID:ID="@+ID/circlePageIndicator"        androID:layout_wIDth="match_parent"        androID:layout_height="wrap_content"        app:fillcolor="@color/colorPrimary"        app:strokecolor="@color/lightGrey"/></linearLayout>

然后,您需要初始化PageIndicator,并设置其VIEwPager.这是在onCreate ….()方法中完成的,无论你使用什么.作为基本规则:此部分应与返回视图的方法相同.我的例如是在onCreateDialog()方法中,因为我在Dialog中有一个VIEwPager.

@OverrIDepublic Dialog onCreateDialog(Bundle savedInstanceState) {    LayoutInflater inflater = getActivity().getLayoutInflater();    // Inflate vIEw    vIEw = inflater.inflate(R.layout.fragment_vIEwpager,null);    // Initialize vIEwpager and set max amount of off screen pages    mPager = (VIEwPager) vIEw.findVIEwByID(R.ID.pager);    mPager.setoffscreenPagelimit(3);    // Initialize pageradapter and set adapter to vIEwpager    mPagerAdapter = new SettingsAdapter(inflater);    mPager.setAdapter(mPagerAdapter);    mPagerAdapter.notifyDataSetChanged();    // Initialize circlePageIndicator and set vIEwpager for it    CirclePageIndicator circlePageIndicator = (CirclePageIndicator) vIEw.findVIEwByID(R.ID.circlePageIndicator);    circlePageIndicator.setVIEwPager(mPager);}

如果我没记错的话,应该是全部.
作为参考,您可以在此处查看此VIEwPagerIndicator的网站:
http://viewpagerindicator.com

请注意:据我所知,您无需从本网站下载任何内容(至少在使用AndroID Studio时不会).你做的第一步应该是准备好VPI.

希望这可以帮助.随意要求澄清.同样,我无法保证这正是它的工作方式,但它应该让你前进.

总结

以上是内存溢出为你收集整理的是否有默认的DotsPageIndicator for Android mobile(不穿)?全部内容,希望文章能够帮你解决是否有默认的DotsPageIndicator for Android mobile(不穿)?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1123755.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存