0

I have 5 images arranged horizontally in a scroll view, along with 5 small dots and a scrollbar thumb. and visual representation of the images that users can scroll through horizontally, with navigation dots and a scrollbar to indicate the current position.

I have XML code below

<HorizontalScrollView
        android:id="@+id/horizontalScrollView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="none"
        app:layout_constraintTop_toBottomOf="@id/horizontalScrollView">


        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <!-- Add your content here -->

            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="371dp"
                android:layout_height="310dp"
                android:src="@drawable/img_7"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.0" />

            <ImageView
                android:id="@+id/imageView3"
                android:layout_width="371dp"
                android:layout_height="310dp"
                android:src="@drawable/img_8"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.0" />

            <ImageView
                android:id="@+id/imageView4"
                android:layout_width="371dp"
                android:layout_height="310dp"
                android:src="@drawable/img_9"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.0" />

            <ImageView
                android:id="@+id/imageView5"
                android:layout_width="371dp"
                android:layout_height="310dp"
                android:src="@drawable/img_10"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.0" />

            <ImageView
                android:id="@+id/imageView6"
                android:layout_width="371dp"
                android:layout_height="310dp"
                android:src="@drawable/img_11"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintVertical_bias="0.0" />

        </LinearLayout>

    </HorizontalScrollView>


    <RelativeLayout
        android:layout_width="325dp"
        android:layout_height="297dp"
        android:layout_marginStart="26dp"
        android:layout_marginTop="290dp"
        app:layout_constraintTop_toTopOf="@id/horizontalScrollView"
        app:layout_constraintLeft_toLeftOf="parent">

        <ImageView
            android:id="@+id/imageView7"
            android:layout_width="16dp"
            android:layout_height="20dp"
            android:layout_marginStart="136dp"
            android:layout_marginTop="270dp"
            android:src="@drawable/blankdot"
            app:layout_constraintStart_toStartOf="parent"
             />

        <ImageView
            android:id="@+id/imageView8"
            android:layout_width="16dp"
            android:layout_height="20dp"
            android:layout_marginStart="156dp"
            android:layout_marginTop="270dp"
            android:src="@drawable/blankdot"
            app:layout_constraintStart_toStartOf="parent"
            />

        <ImageView
            android:id="@+id/imageView9"
            android:layout_width="16dp"
            android:layout_height="20dp"
            android:layout_marginStart="176dp"
            android:layout_marginTop="270dp"
            android:src="@drawable/blankdot"
            app:layout_constraintStart_toStartOf="parent"
            />

        <ImageView
            android:id="@+id/imageView10"
            android:layout_width="16dp"
            android:layout_height="20dp"
            android:layout_marginStart="196dp"
            android:layout_marginTop="270dp"
            android:src="@drawable/blankdot"
            app:layout_constraintStart_toStartOf="parent"
             />

        <ImageView
            android:id="@+id/imageView11"
            android:layout_width="16dp"
            android:layout_height="20dp"
            android:layout_marginStart="216dp"
            android:layout_marginTop="270dp"
            android:src="@drawable/blankdot"
            app:layout_constraintStart_toStartOf="parent"
             />
    </RelativeLayout>

Below is my java code

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_search, container, false);

        final ImageView imageView2 = view.findViewById(R.id.imageView2);
        final ImageView imageView3 = view.findViewById(R.id.imageView3);
        final ImageView imageView4 = view.findViewById(R.id.imageView4);
        final ImageView imageView5 = view.findViewById(R.id.imageView5);
        final ImageView imageView6 = view.findViewById(R.id.imageView6);
        
        //dots images
        final ImageView imageView7 = view.findViewById(R.id.imageView7);
        final ImageView imageView8 = view.findViewById(R.id.imageView8);
        final ImageView imageView9 = view.findViewById(R.id.imageView9);
        final ImageView imageView10 = view.findViewById(R.id.imageView10);
        final ImageView imageView11 = view.findViewById(R.id.imageView11);

        final HorizontalScrollView horizontalScrollView = view.findViewById(R.id.horizontalScrollView);

//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//            horizontalScrollView.setOnScrollChangeListener(new View.OnScrollChangeListener() {
//                @Override
//                public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
//                  
//                }
//            });
//        }


        return view;
    }

I don't know what to do with setOnScrollChangeListener to set respective dot to "colordot" instead of "blankdot" as image Resource. is there any other way we can do it without using setOnScrollChangeListener

I don't know what to do with setOnScrollChangeListener to set respective dot to "colordot" instead of "blankdot" as image Resource. is there any other way we can do it without using setOnScrollChangeListener

0 Answers0