Gridlayout動態添加


//類似數組[行, 列]
//表示起始位置為0,占據2行
GridLayout.Spec rowSpec=GridLayout.spec(0, 2, GridLayout.UNDEFINED);
//表示起始位置為1,占據1列
GridLayout.Spec columnSpec=GridLayout.spec(i, 1, GridLayout.UNDEFINED);
GridLayout.LayoutParams params=new GridLayout.LayoutParams(rowSpec, columnSpec);
gridlayout.addView(view, params);


此外xml中也要預先定好多少行多少列
<android.support.v7.widget.GridLayout
    android:id="@+id/gridlayout"
    app:rowCount="10"
    app:columnCount="6"
    android:background="@mipmap/ic_chat_bg"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</android.support.v7.widget.GridLayout>

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM