带圆圈指示的Android滑动屏幕

带圆圈指示的Android滑动屏幕,android,android-viewpager,viewpagerindicator,Android,Android Viewpager,Viewpagerindicator,我是android新手,我需要一些关于如何创建带有圆圈指示器的教程的基本说明,如下图所示 我用过ViewPager,但它会将整个屏幕和我的圆圈图像一起移动,看起来不太好。我正在读JakeWhatron的viewPageIndicator,但我正在寻找解决问题的核心解决方案。使用带CirclePageAdapter的ViewPager <com.movie.bms.utils.customcomponents.CustomViewPager android:id="@+id

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


我用过ViewPager,但它会将整个屏幕和我的圆圈图像一起移动,看起来不太好。我正在读JakeWhatron的viewPageIndicator,但我正在寻找解决问题的核心解决方案。

使用带CirclePageAdapter的ViewPager

<com.movie.bms.utils.customcomponents.CustomViewPager
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white"/>

    <com.movie.bms.utils.customcomponents.CirclePageIndicator
        android:id="@+id/circle_page_indicator"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        />
检查这个答案以获得更好的解释


这就是如何使用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>
为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>

那你想搬什么?只是文字?这是我目前正在使用的应用程序的一个例子-我使用了Jake Whatrons library顺便说一句:)你想要类似的东西吗?是的,我只想移动文本。顺便说一句,您的登录屏幕看起来很棒!嗨,edwinj!谢谢你提供的详细信息。我不理解安卓在这件事上能从你的建议中找出一切。我应该把onCreate部分的最后一位放在哪里?目前我有:
WelcomePagerAdapter类
WelcomePagerAdapter_layout.xml
fragment_a.xml
我还需要更多吗?谢谢你的帮助和帮助support@Lenny您可以将它放在片段的onCreateView部分的任何位置。(如果您正在使用活动btw,只需再次创建):)谢谢!如果我想在你的视频中看到运动图像,我应该把它们放在哪里?@edwinj。如何将此库下载并导入android studio?@edwinj。我下载此arr文件并将其导入android studio-但它显示:
错误:配置项目时出现问题:app'>找不到library.aar(com.viewpagerindicator:library:2.4.1)。在以下位置搜索:https://jcenter.bintray.com/com/viewpagerindicator/library/2.4.1/library-2.4.1.aar
。我该怎么办?请帮忙!!!
<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>
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);

    }
}
<?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>
    // 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);