我想使用GridLayout(不是GridView)作为象棋或棋子等游戏的棋盘.由于我有点不愿意使用带有64个子视图的xml文件,我尝试以编程方式添加它们.
为了简单起见,我开始使用TextViews作为GridLayout的子视图.
我的问题是视图不是均匀分布的,我不知道如何在我的java代码中获得均匀分布.设置layout_columnWeight和layout_rowWeight没有类似“setWeight()”的方法.
目前,这是我的activity_dynamic_grid_layout.xml:
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_width="match_parent"
android:layout_height="80dp"
android:id="@+id/ivlogo"
android:background="#ff0000"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
android:id="@+id/grid_layout"
android:background="#004080"
android:layout