android 利用gridview布局界面 做个OA界面 模仿在360的样式。

今天我们就学习一下利用GridView来布局页面,做个OA界面,模仿在360手机卫士的样式。

准备工作,图片我是参考别人的,直接拿来用的,主要目的学习AndroidGridView 如何布局!

第一步,新建android程序:如图

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <stroke
        android:width="0.5dip"
        android:color="#ff505050" />

    <corners android:radius="2dip" >
    </corners>

	<gradient android:startColor="#ff505050"
	    android:centerColor="#ff383030"
	    android:endColor="#ff282828"
	    />
</shape>


创建完毕后,整个工程如上图所示。

2.利用GridView建立九宫格式的布局界面,九宫格的内容如下:"新闻公告", "即时通讯","文档管理", "移动审批", "我的考勤", "我的邮件",
// "SIM卡应用","通讯录管理", "设置中心",然后再准备一下相应在9张图片(图片是我参考别人的),格式为. PNG,png格式的图片支持background透明。图片如下:



3. 首先把图片资源添加到res->drwable文件下,拖动图片直接接入既可。如图所示:


4.接下来设计activity_main.xml文件,这是程序运行在主布局界面:参考下面布局内容:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/backgroundcolor"
    android:orientation="vertical" >

    <LinearLayout
      
        android:layout_width="match_parent"
        android:layout_height="40dip"
        android:background="@drawable/title_background"
        android:gravity="center_horizontal|center_vertical"
        android:orientation="vertical" >
        <TextView 
                    android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#FFF8F8F8"
        android:textSize="22sp"
        android:text="手机OA综合管理平台"
            />
    </LinearLayout>

    <GridView
        android:listSelector="@drawable/item_background_selector"
        android:id="@+id/gv_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="10dip"
        android:numColumns="3">
    </GridView>

</LinearLayout>

5.大家可以看出布局文件中:



 android:background="@color/backgroundcolor"
 android:background="@drawable/title_background"
 android:listSelector="@drawable/item_background_selector"
这些我都单独的放到格自的XML文件中,如下所示:



title_background.xml


color.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="backgroundcolor">#ff404040</color>
	<color name="textcolor">#ffd0d0d0</color>
    
</resources>


item_background_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">


    <item android:drawable="@drawable/item_background" android:state_enabled="true" android:state_window_focused="false"/>
    <item android:drawable="@drawable/item_background_selected" android:state_pressed="true"/>
    <item android:drawable="@drawable/item_background" android:state_focused="true"/>
    <item android:drawable="@drawable/item_background"/>


</selector>
/
期中 
item_background_selector.xml 需要
item_background.xml、item_background_selected.xml
///

如下所示:
/

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >


    <stroke
        android:width="0.5dip"
        android:color="#ff505050" />


    <corners android:radius="2dip" >
    </corners>


	<gradient android:startColor="#ff404040"
	    android:centerColor="#ff383838"
	    android:endColor="#ff404040"
	    />
</shape>


/
item_background_selected.xml
//

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >


    <stroke
        android:width="0.5dip"
        android:color="#ff9d9d9d" />


    <corners android:radius="2dip" >
    </corners>


	<gradient android:startColor="#ff9d9d9d"
	    android:centerColor="#ff9e9e9e"
	    android:endColor="#ff9d9d9d"
	    />
</shape>

6.做好这些布局文件后,就可以先预览一下刚下设计在成果,如果所示P:


可以看到GridView还是空的,下面我们就来实现这个GridView。










评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值