How to set border of GridView on Android

后端 未结 4 1858
小蘑菇
小蘑菇 2020-12-05 08:57

How to set border of GridView.
Such as Divider and DividerHeight of ListView.
Or how to display the border.

4条回答
  •  眼角桃花
    2020-12-05 09:22

    Here are some examples of borders in a GridView.

    GridView Borders

    You can see where I defined the Red and Blue borders in my XML.

    This is my main.xml Layout:

    
    
        
    
    
    

    The thickness of the Red border is controlled GridView's layout_margin attribute and the Blue borders are controlled by horizontalSpacing and verticalSpacing.

    To make the black cell backgrounds I used this layout and saved it as list_item.xml:

    
    

    My Activity:

    public class Example extends Activity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            String[] array = new String[] {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"};
            List list = new ArrayList(Arrays.asList(array));
            GridView grid = (GridView) findViewById(R.id.gridview);
            grid.setAdapter(new ArrayAdapter(this, R.layout.list_item, list));
        }
    }
    

提交回复
热议问题