簡體   English   中英

鴻蒙如何實現頁面滑動?

[英]How to implement page sliding for Harmony OS?

如何在 Harmony OS(JAVA) 中為 GridView 項目實現頁面滑動? 這是我的代碼示例。

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));
        }
    }
}

可以在 GridView 外面包裹一個 ScrollView,將 ScrollView 的寬高設置為固定值或者match_parent來實現滑動效果。

下面以GridView繼承的TableLayout為例:

<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>

如果問題依舊,請把GridAdapter的代碼貼出來讓我們檢查。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM