简体   繁体   中英

GridView with one and two columns simultaneously

I want to create a GridView for my Main Menu, but it should have one and two columns simultaneously. What do I mean by that? will have only one wide icon (actually "are" to press will be wide) but row will have 2 icons. 只有一个宽图标(实际上“按”将是宽的),而行将有2个图标。 Here is the picture to make it clear. What's the solution?

GridView with one and two columns

Natively you won't be able to do that with a gridview, have different columns per row that is.

You can however, as Adinia suggested, achieve the same effect by using either a Gridview or List view and rather than changing the number of columns, instead change the content rendered in the cells.

You will have to create your own adapter, you could for example extend the SimpleCursorAdapter, when you do this you can then override the getView() method

public class YouCustomAdapter extends SimpleCursorAdapter

    public View getView(int position, View convertView, ViewGroup parent) {
        if (showOneButton)
        {
            convertView = inflater.inflate(R.layout.onebutton, parent, false);
        }else{
            convertView = inflater.inflate(R.layout.twobutton, parent, false);
        }
    }

etc.

Where the R.layout.onebutton and twobutton are xml layouts with either one or two buttons defined.

However, if you don't have anything more than what's shown in your image (ie the two rows), then you don't need a gridview at all and can just use relative, linear or table layout.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM