Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. android:orientation="vertical"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent">
  7.  
  8. <ImageView
  9. android:id="@+id/image_view"
  10. android:layout_height="wrap_content"
  11. android:layout_width="wrap_content"
  12. android:scaleType="centerCrop"
  13. />
  14.  
  15. <TextView
  16. android:id="@+id/myImageViewText"
  17. android:layout_width="wrap_content"
  18. android:layout_height="wrap_content"
  19. android:layout_alignLeft="@+id/image_view"
  20. android:layout_alignTop="@+id/image_view"
  21. android:layout_alignRight="@+id/image_view"
  22. android:layout_alignBottom="@+id/image_view"
  23. android:layout_margin="1dp"
  24. android:gravity="bottom"
  25. android:textSize="30dp"
  26. android:text="Welcome to DriftFan"
  27. android:textStyle="bold"
  28. android:textAllCaps="true"
  29. android:textColor="@color/colorPrimary"/>
  30. </RelativeLayout>
  31.  
  32. <android.support.v4.view.ViewPager
  33. android:id="@+id/view_pager"
  34. android:layout_width="fill_parent"
  35. android:layout_height="204dp"
  36. android:scaleType="centerCrop"
  37. ></android.support.v4.view.ViewPager>
  38.  
  39. public class myTimerTask extends TimerTask {
  40.  
  41. @Override
  42. public void run() {
  43.  
  44. if (getActivity()== null) {
  45. return;
  46.  
  47. }
  48. getActivity().runOnUiThread(new Runnable() {
  49. @Override
  50. public void run() {
  51.  
  52.  
  53. if (viewPager.getCurrentItem() == 0) {
  54. viewPager.setCurrentItem(1);
  55. } else if (viewPager.getCurrentItem() == 1) {
  56. viewPager.setCurrentItem(2);
  57. } else if (viewPager.getCurrentItem() == 2) {
  58. viewPager.setCurrentItem(3);
  59.  
  60. }
  61.  
  62.  
  63. }
  64.  
  65.  
  66. });
  67. }
  68. }
  69. }
  70.  
  71. public class ViewPagerAdapter extends PagerAdapter {
  72.  
  73. private Context context;
  74. private LayoutInflater layoutInflater;
  75. private Integer[] images = {R.drawable.img1, R.drawable.img2, R.drawable.img3, R.drawable.img4};
  76.  
  77. public ViewPagerAdapter(Context context) {
  78. this.context = context;
  79. }
  80.  
  81. @Override
  82. public int getCount() {
  83. return images.length;
  84. }
  85.  
  86. @Override
  87. public boolean isViewFromObject(View view, Object object) {
  88. return view == object;
  89. }
  90.  
  91. @Override
  92. public Object instantiateItem(ViewGroup container, int position) {
  93.  
  94. layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  95. View view = layoutInflater.inflate(R.layout.custom_layout, null);
  96. ImageView imageView = (ImageView) view.findViewById(R.id.image_view);
  97. imageView.setImageResource(images[position]);
  98.  
  99. ViewPager vp = (ViewPager) container;
  100. vp.addView(view, 0);
  101. return view;
  102. }
  103.  
  104. @Override
  105. public void destroyItem(ViewGroup container, int position, Object object) {
  106.  
  107. ViewPager vp = (ViewPager)container;
  108. View view = (View) object;
  109. vp.removeView(view);
  110.  
  111.  
  112.  
  113. }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement