Android滑动屏幕并显示圆圈

Android滑动屏幕并显示圆圈,第1张

概述我是android的新手,我需要一些有关如何使用圆圈指示器创建教程的基本说明,如下图所示我曾经使用过ViewPager,但是它将整个屏幕与我的圆圈图像一起移动,看起来不太好.我正在阅读有关JakeWhatron的viewPageIndicator的信息,但是我正在寻找解决问题的核心方法.解决方法:这就是使用Ja

我是android的新手,我需要一些有关如何使用圆圈指示器创建教程的基本说明,如下图所示


我曾经使用过VIEwPager,但是它将整个屏幕与我的圆圈图像一起移动,看起来不太好.我正在阅读有关JakeWhatron的vIEwPageIndicator的信息,但是我正在寻找解决问题的核心方法.

解决方法:

这就是使用Jake Whatron的库获取带有文本的圆圈指示器的方法

将此添加到build.gradle文件

compile 'com.vIEwpagerindicator:library:2.4.1@aar'

将所需的图像作为主布局的背景.

<relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:tools="http://schemas.androID.com/tools"    androID:ID="@+ID/hello_layour"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:background="@drawable/login_background_image"  // add your background image here    tools:context=".HelloActivity"></relativeLayout>

将此添加到您想要的指标和文本的位置

<linearLayout    androID:ID="@+ID/imageVIEw"    androID:layout_wIDth="match_parent"    androID:layout_height="300dp"    androID:layout_centerHorizontal="true"    androID:orIEntation="vertical">    <androID.support.v4.vIEw.VIEwPager // the actual text you want will be shows here        androID:ID="@+ID/pager"        androID:layout_wIDth="fill_parent"        androID:layout_height="0dp"        androID:layout_weight="1" />    <com.vIEwpagerindicator.CirclePageIndicator // this is the circular indicator         androID:ID="@+ID/indicator"        androID:layout_wIDth="fill_parent"        androID:layout_height="wrap_content"        androID:padding="10dip" /></linearLayout>

创建一个新类,添加以下数据(这是vIEwpager的适配器):

package com.your.packagename;import androID.content.Context;import androID.support.v4.vIEw.PagerAdapter;import androID.support.v4.vIEw.VIEwPager;import androID.vIEw.LayoutInflater;import androID.vIEw.VIEw;import androID.vIEw.VIEwGroup;import androID.Widget.ImageVIEw;import androID.Widget.relativeLayout;import androID.Widget.TextVIEw;public class WelcomePagerAdapter extends PagerAdapter {    // Declare Variables    private Context context;    private String[] Title;    private String[] description;    private LayoutInflater inflater;    public WelcomePagerAdapter(Context context, String[] Title, String[] description) {        this.context = context;        this.Title= Title;        this.description= description;    }    @OverrIDe    public int getCount() {        return Title.length;    }    @OverrIDe    public boolean isVIEwFromObject(VIEw vIEw, Object object) {        return vIEw == ((relativeLayout) object);    }    @OverrIDe    public Object instantiateItem(VIEwGroup container, int position) {        // Declare Variables        TextVIEw TitleVIEw;        TextVIEw descriptionVIEw;        inflater = (LayoutInflater) context            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);        // layout inflator        VIEw itemVIEw = inflater.inflate(R.layout.welcome_pager, container,            false);        // Title text holder        TitleVIEw = (TextVIEw) itemVIEw.findVIEwByID(R.ID.welcome_Title);        TitleVIEw.setText(Title[position]);        // description text holder        descriptionVIEw= (TextVIEw) itemVIEw.findVIEwByID(R.ID.welcome_description);        descriptionVIEw.setText(description[position]);        // add vIEwpager_item.xml to VIEwPager        ((VIEwPager) container).addVIEw(itemVIEw);        return itemVIEw;    }    @OverrIDe    public voID destroyItem(VIEwGroup container, int position, Object object) {        // Remove vIEwpager_item.xml from VIEwPager        ((VIEwPager) container).removeVIEw((relativeLayout) object);    }}

为vIEwpager项的布局创建一个xml文件.

<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:layout_centerHorizontal="true"    xmlns:tools="http://schemas.androID.com/tools">    <TextVIEw        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:textAppearance="?androID:attr/textAppearanceLarge"        androID:ID="@+ID/welcome_Title"        androID:paddingtop="15dp"        androID:textSize="25sp"        androID:textcolor="#fff"        androID:layout_centerHorizontal="true" />    <TextVIEw        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:textAppearance="?androID:attr/textAppearanceMedium"        androID:layout_below="@+ID/welcome_Title"        androID:ID="@+ID/welcome_description"        androID:layout_centerHorizontal="true"        androID:gravity="center_horizontal"        androID:padding="15sp"        androID:textcolor="#fff" /></relativeLayout>

现在,最后将其添加到您的教程活动的onCreate()部分中:

    // pager Titles    String[] Titles = new String[]{"Random Title One", "Random Title Two",            "Random Title Three", "Random Title Four"};    // pager descriptions    String[] descriptions= new String[]{"random small description example", "random small description example",            "random small description example", "random small description example"};    // Locate the VIEwPager in vIEwpager_main.xml    VIEwPager vIEwPager = (VIEwPager) findVIEwByID(R.ID.pager);    // Pass results to VIEwPagerAdapter Class    PagerAdapter adapter = new WelcomePagerAdapter(this, Titles, descriptions);    // Binds the Adapter to the VIEwPager    vIEwPager.setAdapter(adapter);    // VIEwPager Indicator    CirclePageIndicator mIndicator = (CirclePageIndicator) findVIEwByID(R.ID.indicator);    mIndicator.setVIEwPager(vIEwPager);
总结

以上是内存溢出为你收集整理的Android滑动屏幕并显示圆圈全部内容,希望文章能够帮你解决Android滑动屏幕并显示圆圈所遇到的程序开发问题。

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

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

原文地址: http://outofmemory.cn/web/1090425.html

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

发表评论

登录后才能评论

评论列表(0条)

保存