05
2017
10

GridView布局

2017.10.03今天下午学习了Gridview布局,大体上和ListView是一样的,但它有几个特殊的属性
android:numColumns=”3”
android:verticalSpacing=”10dp” 竖直间距
android:horizontalSpacing=”10dp”水平间距

<GridView  android:id="@+id/gridview" android:layout_width="368dp" android:layout_height="495dp" android:numColumns="3" android:verticalSpacing="10dp" android:horizontalSpacing="10dp" tools:layout_editor_absoluteX="8dp" tools:layout_editor_absoluteY="8dp" />
public class MainActivity extends AppCompatActivity {
    private GridView gridView;
    private SimpleAdapter simpleAdapter;
    private List<Map<String,Object>> data_list;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        gridView=(GridView)findViewById(R.id.gridview);
        data_list=new ArrayList<Map<String, Object>>();
        simpleAdapter=new SimpleAdapter(this,getData(),R.layout.gridview_item,new String[]{"pic","text"},new int[]{R.id.imageView,R.id.textView});
        gridView.setAdapter(simpleAdapter);
    }
    private List<Map<String,Object>> getData(){
        for(int i=0;i<9;i++) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("pic", R.mipmap.ic_launcher);
            map.put("text","无敌的天宇");
            data_list.add(map);
        }
        return data_list;
    }
}
上一篇:DataPicker和TimePicker 下一篇:使用 RecyclerView 实现简单时间轴