Android的实施像一个在主屏幕上的网页计数器 [英] Android Implement a page counter like the one on the home screen

查看:105
本文介绍了Android的实施像一个在主屏幕上的网页计数器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道怎么做的页面/视图计数器(小点),如一个在主屏幕的例子吗?

Does anyone know of an example of how to do the page/view counter (little dots) like the one on home screen?

像这个例子:

感谢

推荐答案

<一个href="http://developer.android.com/reference/android/support/v4/view/PagerTitleStrip.html">PagerTitleStrip是您使用与 ViewPager 来表示你在哪一页。这件事情您添加到您的 XML

PagerTitleStrip is what you use with ViewPager to indicate what page you're on. It's something you add to your XML.

布局XML

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center" >

    <android.support.v4.view.PagerTitleStrip
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top" />
</android.support.v4.view.ViewPager>

</LinearLayout>

而在你的PagerAdapter

@Override
    public CharSequence getPageTitle (int position) {
        return "Your static title";
    }

不过, PagerTitleStrip 不是很定制的,但 ViewPagerIndicator 是非常定制,包括你正在寻找的虚线指示。你需要的主题是重新创建画面在你的OP。

However, PagerTitleStrip isn't very customizable, but ViewPagerIndicator is very customizable and includes the dotted indicator that you're looking for. You'll need to theme it to recreate the picture in your OP.

圆指标与 ViewPagerIndicator

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.viewpagerindicator.sample"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    />
<com.viewpagerindicator.CirclePageIndicator
    android:id="@+id/indicator"
    android:padding="10dip"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    />

</LinearLayout>

然后在你的code

CirclePageIndicator mIndicator = (CirclePageIndicator)findViewById(R.id.indicator);
        mIndicator.setViewPager(mPager);

ViewPagerExtensions 是另一个开源库,它提供了自定义视图 ViewPager 你可能会感兴趣。

ViewPagerExtensions is another open source library that offers custom views for ViewPager you might be interested in.

这篇关于Android的实施像一个在主屏幕上的网页计数器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆