我在 gridview 中有 3 列,每个单元格中都有一个按钮,但第一列应该比其他列更薄,但我无法做到这一点,这里是代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="@+id/cell"
android:layout_height="12dp"
android:layout_width="wrap_content"
android:background="#ffffff"
android:textColor="#000000"
/>
</RelativeLayout>
这里是java代码:
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if (row == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.cell, parent, false);
}
gridcell = (Button) row.findViewById(R.id.cell);
String tmp = list.get(position);
gridcell.setTextSize(10);
gridcell.setText(tmp);
//first column
if ((position % 3) == 0) {
gridcell.setBackgroundColor(Color.LTGRAY);
//width should be changed
gridcell.setWidth(5);
} else {
gridcell.setBackgroundColor(Color.BLUE);
gridcell.setWidth(50);
}
return row;
}
有什么建议么