有两个属性android:layout_columnWeight和layout_rowWeight在LinearLayout中像layout_weight一样工作。这在API 21中得到支持。对于较旧的Android设备,请使用v7支持库中的GridLayout。

这些属性将允许您根据分配给每个列的值来调整列的宽度/高度。公式如下(column_weight / sum_of_column_weight)* gridLayout_width = column_width。

这是一个示例,它是一个GridView,它的2行和2列均匀分布,每个占据网格的重量和高度的50%。

android:layout_width="match_parent"

android:layout_height="match_parent"

android:columnCount="2"

>

android:text="SEARCH FEE"

android:layout_columnWeight="1"

android:layout_rowWeight="1"

/>

android:layout_columnWeight="1"

android:text="SEARCH FEE"

android:layout_rowWeight="1"

/>

android:text="SEARCH FEE"

android:layout_columnWeight="1"

android:layout_rowWeight="1"

/>

android:layout_columnWeight="1"

android:text="SEARCH FEE"

android:layout_rowWeight="1"

/>

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐