Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <ImageView
- android:id="@+id/image_view"
- android:layout_height="wrap_content"
- android:layout_width="wrap_content"
- android:scaleType="centerCrop"
- />
- <TextView
- android:id="@+id/myImageViewText"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/image_view"
- android:layout_alignTop="@+id/image_view"
- android:layout_alignRight="@+id/image_view"
- android:layout_alignBottom="@+id/image_view"
- android:layout_margin="1dp"
- android:gravity="bottom"
- android:textSize="30dp"
- android:text="Welcome to DriftFan"
- android:textStyle="bold"
- android:textAllCaps="true"
- android:textColor="@color/colorPrimary"/>
- </RelativeLayout>
- <android.support.v4.view.ViewPager
- android:id="@+id/view_pager"
- android:layout_width="fill_parent"
- android:layout_height="204dp"
- android:scaleType="centerCrop"
- ></android.support.v4.view.ViewPager>
- public class myTimerTask extends TimerTask {
- @Override
- public void run() {
- if (getActivity()== null) {
- return;
- }
- getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
- if (viewPager.getCurrentItem() == 0) {
- viewPager.setCurrentItem(1);
- } else if (viewPager.getCurrentItem() == 1) {
- viewPager.setCurrentItem(2);
- } else if (viewPager.getCurrentItem() == 2) {
- viewPager.setCurrentItem(3);
- }
- }
- });
- }
- }
- }
- public class ViewPagerAdapter extends PagerAdapter {
- private Context context;
- private LayoutInflater layoutInflater;
- private Integer[] images = {R.drawable.img1, R.drawable.img2, R.drawable.img3, R.drawable.img4};
- public ViewPagerAdapter(Context context) {
- this.context = context;
- }
- @Override
- public int getCount() {
- return images.length;
- }
- @Override
- public boolean isViewFromObject(View view, Object object) {
- return view == object;
- }
- @Override
- public Object instantiateItem(ViewGroup container, int position) {
- layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- View view = layoutInflater.inflate(R.layout.custom_layout, null);
- ImageView imageView = (ImageView) view.findViewById(R.id.image_view);
- imageView.setImageResource(images[position]);
- ViewPager vp = (ViewPager) container;
- vp.addView(view, 0);
- return view;
- }
- @Override
- public void destroyItem(ViewGroup container, int position, Object object) {
- ViewPager vp = (ViewPager)container;
- View view = (View) object;
- vp.removeView(view);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement