就是我们弄计算机的布局时,都不能平分屏幕的,
当第一行有两个元素时。它们的宽度大小如何平分屏幕?
GridLayout 设置权重属性确实没有毛用,你给他的每个item 布局设置为屏幕的 1/x 不就结了。
final View convertView = LayoutInflater.from(context).inflate(R.layout.people_ly, null);
convertView.setTag(con);
TextView tv =(TextView) convertView.findViewById(R.id.tv_names);
LinearLayout.LayoutParams lp=new LayoutParams(ScreenUtils.getScreenWidth()/COUNT, LinearLayout.LayoutParams.WRAP_CONTENT);
convertView.setLayoutParams(lp);
mGridLayout.setColumnCount(COUNT); 这里的count 为我设置的列 为 4
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="2"
android:rowCount="2">
<Button
android:layout_column="0"
android:layout_row="0" />
<Button
android:layout_column="1"
android:layout_gravity="fill_vertical"
android:layout_row="0"
android:layout_rowSpan="2" />
<Button
android:layout_column="0"
android:layout_row="1" />
子元的layout_weight="0sp"
layout_weight="1"试试
我他妈早就发现GridLayout根本不能设置居中,这个控件根本就他妈的没个屌用,楼上都他妈的傻屌
gridlayout就是tm个SB
"GridLayout does not provide support for the principle of weight, as defined in weight. In general, it is not therefore possible to configure a GridLayout to distribute excess space in non-trivial proportions between multiple rows or columns ... For complete control over excess space distribution in a row or column; use a LinearLayout subview to hold the components in the associated cell group."
官方文档里面说了是不支持的
设置一个属性:android:columnCount="2"就ok了啊!
API 21以上可以用他的这个属性:
android:layout_columnWeight="1"
android:layout_rowWeight="1"
配合
android:rowCount="3"
android:columnCount="2"
可以实现等分