How to implement page sliding for Harmony OS?

Viewed 170

How can I implement page sliding for GridView items in Harmony OS(JAVA)? Here's a sample of my code.

public class GridView extends TableLayout {
    public GridView(Context context) {
        super(context);
    }

    public GridView(Context context, AttrSet attrSet) {
        super(context, attrSet);
    }

    public GridView(Context context, AttrSet attrSet, String styleName) {
        super(context, attrSet, styleName);
    }

    void setAdapter(GridAdapter adapter, LongClickedListener longClickedListener) {
        removeAllComponents();
        for (int i = 0; i < adapter.getComponentList().size(); i++) {
            adapter.getComponentList().get(i).setLongClickedListener(longClickedListener);
            addComponent(adapter.getComponentList().get(i));
        }
    }
}
1 Answers

You can wrap a ScrollView outside the GridView and set the width and height of the ScrollView to a fixed value or match_parent to implement the sliding effect.

The following uses TableLayout inherited by GridView as an example:

<ScrollView
    ohos:height="match_parent"
    ohos:width="match_parent">

    <TableLayout
        ohos:height="match_content"
        ohos:width="match_parent"
        ohos:background_element="#87CEEB"
        ohos:padding="8vp"
        >
     ...
     </<TableLayout>
<ScrollView>

If the problem persists, pls post the GridAdapter code for us to check.

Related