我愿意用这种设计做一个布局。
我正在使用带有三列的GridView。但我不知道的是如何在我的自定义适配器中设置其中一个项目将填满整行。
布局
<GridView
android:id="@+id/grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:numColumns="3"
android:orientation="horizontal">
自定义适配器
private class GridAdapter extends BaseAdapter {
private Context context;
private ArrayList hashmap = new ArrayList<String[]>();
public GridAdapter(Context context, ArrayList<String[]> hashmap) {
this.context = context;
this.hashmap = hashmap;
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View gridView;
if (convertView == null) {
gridView = new View(context);
} else {
gridView = (View) convertView;
}
gridView = inflater.inflate(R.layout.home_grid_item, null);
ImageView imageView = (ImageView) gridView.findViewById(R.id.grid_item_image);
TextView textView = (TextView) gridView.findViewById(R.id.grid_item_label);
String[] temp = (String[]) hashmap.get(position);
imageView.setImageResource(Integer.parseInt(temp[0]));
textView.setText(temp[1]);
return gridView;
}
答案 0 :(得分:0)
您是否尝试将布局宽度从match_parent减小为wrap_content?