How to set auto image slider with the help of sliderlayout in android studio

1k Views Asked by At

How to create auto image slider with the help of com.smarteist.autoimageslider.SliderLayout in android studio

I was trying to create a autoimage slider with the help of com.smarteist.autoimageslider.SliderLayout under the fragment but when i run the the app its show some errors

Errors

  Process: com.example.mycollege, PID: 23523
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mycollege/com.example.mycollege.MainActivity}: android.view.InflateException: Binary XML file line #18: Binary XML file line #18: Error inflating class com.smarteist.autoimageslider.SliderLayout
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2887)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2965)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1669)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:192)
        at android.app.ActivityThread.main(ActivityThread.java:6702)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:826)
     Caused by: android.view.InflateException: Binary XML file line #18: Binary XML file line #18: Error inflating class com.smarteist.autoimageslider.SliderLayout
     Caused by: android.view.InflateException: Binary XML file line #18: Error inflating class com.smarteist.autoimageslider.SliderLayout
     Caused by: java.lang.reflect.InvocationTargetException

fragement_home.XML

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ui.home.homeFragment">
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
      <com.smarteist.autoimageslider.SliderLayout
          android:layout_width="match_parent"
          android:layout_height="250dp"
          android:id="@+id/slider_image"/>
    </LinearLayout>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@color/black"
        android:text="HOME"/>
</ScrollView>
</FrameLayout>

homefragement.java

public class homeFragment extends Fragment {
    private SliderLayout sliderLayout;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_home, container, false);
        sliderLayout = view.findViewById(R.id.slider_image);
        sliderLayout.setIndicatorAnimation(IndicatorAnimations.FILL);
        sliderLayout.setSliderTransformAnimation(SliderAnimations.SIMPLETRANSFORMATION);
        sliderLayout.setScrollTimeInSec(1);
        setsliderview();
        return view;
    }
    private void setsliderview() {
        for (int i = 0; i < 5; i++) {
            DefaultSliderView defaultSliderView = new DefaultSliderView(getContext());
            switch (i) {
                case 0:
                    defaultSliderView.setImageUrl("Imageurl");
                    break;
                case 1:
                    defaultSliderView.setImageUrl("Imageurl");
                    break;
                case 2:
                    defaultSliderView.setImageUrl("Imageurl");
                    break;
                case 3:
                    defaultSliderView.setImageUrl("Imageurl");
                    break;
                case 4:
                    defaultSliderView.setImageUrl("Imageurl");
                    break;
            }
            defaultSliderView.setImageScaleType(ImageView.ScaleType.CENTER_CROP);
            sliderLayout.addSliderView(defaultSliderView);
        }
    }
}
0

There are 0 best solutions below