私はかなりの時間前にこの質問への答えを見つけたが、私はまだこの1つが開いていた忘れてしまったので、私は、私は当時から覚えていると、今それに答えることをしようとするつもりですしています。だから、それは完璧ではないかもしれないことに注意してください。しかし、私はできるだけ良いものにしようとします。
viewPagerIndicator
ライブラリが必要です。あなたが追加する必要があります、
...
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:[email protected]'
}
次:私はこれを行う方法はdependencies
に行き、結果はこのようになるはずですcompile 'com.viewpagerindicator:library:[email protected]'
を追加し、あなたのbuild.gradle (Module: app)
のGradleスクリプトを開くことであると信じてPageIndicator
(あなたのサークルバージョンを選んだ)を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
があるからです。
@Override
public 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
の準備を整えておくべきだったはずです。
これが役に立ちます。ご清聴をお願いします。繰り返しますが、これは正確に動作することを保証するものではありませんが、それはあなたを動かすはずです。
XMLはどの要素を使用する必要がありますか?それはViewpagerの中にあるべきかどうか? – Timmiej93
@ Timmiej93 Viewpagerレイアウトの外側で使用します。 – AKSiddique
しかしそれはどんな要素ですか? XMLタグは閉じますが、XMLタグは開かないでください。 – Timmiej93