Wednesday, 10 October 2018

SliderImage


compile 'me.relex:circleindicator:1.2.2@aar'

Step 1 :

SlidePagerAdapter .java


public class SlidePagerAdapter extends PagerAdapter {
    int[] mResources = {
            R.drawable.ooty,
            R.drawable.ooty2,
            R.drawable.ooty,
            R.drawable.ooty2,
            R.drawable.ooty,
            R.drawable.ooty2,};
    Context mContext;
    LayoutInflater mLayoutInflater;

    public SlidePagerAdapter(Context context) {
        mContext = context;
        mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override    public int getCount() {
        return mResources.length;
    }

    @Override    public boolean isViewFromObject(View view, Object object) {

        return view == ((LinearLayout) object);
    }

    @Override    public Object instantiateItem(ViewGroup container, int position) {
        View itemView = mLayoutInflater.inflate(R.layout.slide, container, false);

        ImageView imageView = (ImageView) itemView.findViewById(R.id.image);
        imageView.setImageResource(mResources[position]);

        container.addView(itemView);

        return itemView;
    }

    @Override    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((LinearLayout) object);
}
}

Step 2:

public class MainActivity extends AppCompatActivity{
ViewPager mPager;
SlidePagerAdapter slidePagerAdapter;
CircleIndicator indicator;
@Overrideprotected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

mPager = (ViewPager) view.findViewById(R.id.pager);
indicator = (CircleIndicator) view.findViewById(R.id.indicator);



slidePagerAdapter = new SlidePagerAdapter(getActivity());
mPager.setAdapter(slidePagerAdapter);
indicator.setViewPager(mPager);
}}


Step 3:

activity_main.xml
<LinearLayout    android:layout_width="match_parent"  
  android:layout_height="wrap_content"    
android:orientation="vertical">
    <LinearLayout        
android:layout_width="match_parent"
        android:layout_height="300dp"  
      android:id="@+id/layout_image" 
       android:orientation="vertical" 
       android:background="@drawable/ooty"  
      android:gravity="center">
        <RelativeLayout        
    android:layout_width="match_parent"   
         android:layout_height="match_parent">
            <android.support.v4.view.ViewPager 
               android:id="@+id/pager"     
           android:layout_width="match_parent" 
               android:layout_height="match_parent"
               android:clickable="false">

            </android.support.v4.view.ViewPager>

            <me.relex.circleindicator.CircleIndicator  
              android:id="@+id/indicator"    
            android:layout_width="match_parent" 
               android:layout_height="48dp"  
              android:layout_alignParentBottom="true"/>

        </RelativeLayout>
    </LinearLayout>
    <LinearLayout


Step 4:

slide.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
 android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView    android:id="@+id/image"
   android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:adjustViewBounds="true"
    android:layout_gravity="center"
    android:src="@drawable/ooty"
    android:scaleType="centerCrop"/>
</LinearLayout>

No comments:

Post a Comment

HOW TO CREATE CIRCLE IMAGE VIEW

Step 1: implementation 'de.hdodenhof:circleimageview:3.0.0' Step 2: <de.hdodenhof.circleimageview.CircleImageView xmlns:ap...