Wenn Sie immer noch eine GridView verwenden möchten, können Sie eine der Zellen ausblenden und die Breite des nächsten erweitern, so dass es die gesamte Breite überspannt. Dies kann in Ihrem RowAdapter erfolgen.
private static LayoutInflater inflater = null;
public class GridRowAdapter extends BaseAdapter
{
private String[] imageURLArray;
public GridRowAdapter(String[] imageURLArray)
{
this.imageURLArray = imageURLArray;
if(inflater == null)
{
inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
}
public int getCount()
{
int iCount = Math.max(imageURLArray.length, 1);
//Reduce the count of items expected by the GridView because 1 item will take up 2 cells
iCount--;
return iCount;
}
public Object getItem(int position)
{
return position;
}
public long getItemId(int position)
{
return position;
}
public View getView(int position, View convertView, ViewGroup parent)
{
View v = convertView;
try
{
if(parent != null)
{
if(position < 2)
{
v = inflater.inflate(R.layout.grid_item_feature, parent, false);
ViewGroup.LayoutParams params = v.getLayoutParams();
if(position == 0)
{
//Extend height and width of the cell on the left
params.height = (itemsGridView.getWidth());
params.width = (itemsGridView.getWidth());
//Write code to show Image or Text
String strImage = imageURLArray[position];
}
else
{
//You must extend the height of this cell too even though you're going to make it disappear
params.height = (itemsGridView.getWidth());
//Hide cell on the right
v.setVisibility(View.GONE);
}
}
else
{
//Reduce the index of the position because we skipped an item
position--;
v = inflater.inflate(R.layout.grid_item, parent, false);
//Write code to show Image or Text
String strImage = imageURLArray[position];
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
return v;
}
}
Danke, habe gerade herausgefunden. –
Eigentlich ist GridLayout derjenige, der zum Überspannen verwendet wird. Es ist in der Support v7-Bibliothek, nicht jar. – MinceMan
@MinceMan: Beachten Sie, dass diese Antwort aus dem Jahr 2009 vor der Einführung von 'GridLayout' stammt. – CommonsWare