Search code examples
javaandroidhuawei-mobile-serviceshuawei-developersharmonyos

How to automatically slide the pages in page slider HarmonyOS?


I have implemented a custom page slider indicator inspired by ArcPageIndicator in HarmonyOS and to test that I wanted to slide the pages using the page slider automatically. How Can I do that in HarmonyOS?


Solution

  • Create a ScrollView component in the XML file under the layout directory. ScrollView requires the support of a layout. The following uses DirectionalLayout as an example.

    <ScrollView
        ohos:id="$+id:scrollview"
        ohos:height="300vp"
        ohos:width="300vp"
        ohos:background_element="#FFDEAD"
        ohos:top_margin="32vp"
        ohos:bottom_padding="16vp"
        ohos:layout_alignment="horizontal_center">
        <DirectionalLayout
            ohos:height="match_content"
            ohos:width="match_content">
            <!-- $media:plant: image resource referenced in the media directory-->
            <Image
                ohos:width="300vp"
                ohos:height="match_content"
                ohos:top_margin="16vp"
                ohos:image_src="$media:plant"/>
            <!-- Add content to be displayed -->
            ...
        </DirectionalLayout>
    </ScrollView>
    

    For more details, see scrollView of the Java UI.