GridView和Spinner的介绍

2017-07-28  本文已影响0人  W_Nicotine

在最近的学习中,我接触了GridView、Spinner。下面我来对他们的简单介绍:

  1. GridView 是 DataGrid的后继控件,在.net framework 2 中,虽然还存在DataGrid,但是GridView已经走上了历史的前台,取代DataGrid的趋势已是势不可挡。GridView和DataGrid功能相似,都是在web页面中显示数据源中的数据,将数据源中的一行数据,也就是一条记录,显示为在web页面上输出表格中的一行。在https://baike.baidu.com/item/gridview/6027180?fr=aladdin 中有对GridView的简单介绍。
图一

http://blog.csdn.net/leichelle/article/details/7951290

  1. Spinner是一个提供了下拉列表样式的布局空控件,如下图所示:



    我本次主要学习这个控件来对所选的学期进行一个下拉选择,代码如下:
    修改mainActivity.java

     protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        spinner = (Spinner) this.findViewById(R.id.spinner1);
        ArrayAdapter adapter = new ArrayAdapter(this,
                android.R.layout.simple_spinner_item, new String[] { " ","16-17-2", "16-17-1",
                "15_16-2","15_16-1","14_15-2","14_15-1","13_14-2"
                ,"13_14-1","12_13-2","12_13-1","11_12-2","11_12-1","10_11-2","10_11-1","09_10-2","09_10-1","08_09-2","08_09-1","07_08-2"
                ,"07_08-1","06_07-2","06_07-1","05_06-2","05_06-1","04_05-2","04_05-1","03_04-2","03_04-1","02_03-2","02_03-1","01_02-2"
                ,"01_02-1" });

        //设置下拉样式
        adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
        spinner.setAdapter(adapter);
    }

修改activity_main

        <Spinner
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:id="@+id/spinner1"
            android:layout_marginTop="40sp"/>

效果如下图

图四

http://www.114la.com/other/rgb.htm

如下图

图三
上一篇下一篇

猜你喜欢

热点阅读