也来遵守android UI 规范--GridView主界面设计

1 概览

l  Androiduipatterns网站针对android应用界面的设计提出了一些规范性的建议,可以参考参考

l  GridView实现主界面

2 实现的截图

 

主要实现代码

3.1 定义GridView

GridView gridview = (GridView)findViewById(R.id.indexMenu);

3.2 初始化适配器

SimpleAdapter myAdapter = new SimpleAdapter(
				this, //context ,上下文
				ImageItem,//data , 数据源
				R.layout.item,//resource, 一个定义列表项目的视图布局的资源唯一标识。布局文件将至少应包含那些在to中定义了的名称。
				// 一个将被添加到Map上关联每一个项目的列名称的列表
				new String[] { "ItemImage", "ItemText" },
				//  from ,一系列被关联的Item的数据源名字
				new int[] { R.id.ItemImage, R.id.ItemText });//to,应该在参数from显示列的视图。这些应该全是TextView。在列表中最初的N视图是从参数from中最初的N列获取的值。

3.3 绑定适配器

gridview.setAdapter(myAdapter);

 

3.4 增加每个Item的监听

gridview.setOnItemClickListener(newItemClickListener());//ItemClickListener为自定义类

 

相关布局

 

4.1 index.xml

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

    <GridView
        android:id="@+id/indexMenu"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:columnWidth="120dp"
        android:gravity="center"
        android:horizontalSpacing="10dp"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="0dp"
        android:layout_marginRight="0dp"
        android:numColumns="auto_fit"
        android:stretchMode="columnWidth"
        android:verticalSpacing="20dp"
         >
    </GridView>


</LinearLayout>


 

4.2 Item布局

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


    
    <ImageView
         android:id="@+id/ItemImage"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:gravity="center"
     />
    
      <TextView
        android:id="@+id/ItemText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:textColor="#000000"
        android:text="" 
        android:textColorHighlight="#0072E3"
        />
    

</LinearLayout>


 

4.3 自定义菜单栏布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/screen"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

        <TextView
        android:id="@+id/head_center_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="" 
        android:textColor="#FFFFFF"
        />
    
    <Button
        android:id="@+id/TitleHomeBtn"
        android:layout_width="30dp"   
        android:layout_height="30dp"
        android:background="@drawable/home"
        android:gravity="center"
        android:layout_marginTop="0dp"
        android:layout_alignParentLeft="true"/>
    	
    	
   <Button
    	android:id="@+id/TitleBackBtn"
        android:layout_width="30dp"   
        android:layout_height="30dp"
        android:background="@drawable/back"
        android:gravity="center"
        android:layout_marginTop="0dp"
        android:layout_alignParentRight="true"/>

</RelativeLayout>


5 GridView的XML属性

属性描述                                       

android:columnWidth

列宽

android:gravity

所处布局的位置

android:horizontalSpacing

两列之间的间距

android:numColumns

设置列数

android:stretchMode

缩放模式

android:verticalSpacing

两行之间的间距

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个简单的 ASP.NET GridView 界面设计,你可以根据自己的需求进行修改和优化。 首先,我们需要在页面中添加一个 GridView 控件,代码如下: ```aspx <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CssClass="table table-striped table-bordered" GridLines="None"> <Columns> <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" /> <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /> <asp:BoundField DataField="Age" HeaderText="Age" SortExpression="Age" /> <asp:BoundField DataField="Gender" HeaderText="Gender" SortExpression="Gender" /> </Columns> </asp:GridView> ``` 然后,我们需要为 GridView 定义样式。这里我使用了 Bootstrap 提供的表格样式,你可以根据自己的需求选择其他样式。代码如下: ```css .table { width: 100%; max-width: 100%; margin-bottom: 20px; border-collapse: collapse; border-spacing: 0; background-color: transparent; } .table-bordered { border: 1px solid #ddd; } .table-striped>tbody>tr:nth-of-type(odd) { background-color: #f9f9f9; } .table>thead>tr>th { border-bottom: 2px solid #ddd; vertical-align: middle; } .table>tbody>tr>td { border-top: 1px solid #ddd; vertical-align: middle; } ``` 最后,我们需要在代码中填充 GridView 数据。这里我使用了一个简单的 List 对象作为数据源,你可以根据自己的需求选择其他数据源。代码如下: ```csharp protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { List<Person> persons = new List<Person> { new Person { ID = 1, Name = "张三", Age = 20, Gender = "男" }, new Person { ID = 2, Name = "李四", Age = 25, Gender = "女" }, new Person { ID = 3, Name = "王五", Age = 30, Gender = "男" }, new Person { ID = 4, Name = "赵六", Age = 35, Gender = "女" } }; GridView1.DataSource = persons; GridView1.DataBind(); } } public class Person { public int ID { get; set; } public string Name { get; set; } public int Age { get; set; } public string Gender { get; set; } } ``` 这样,一个简单的 ASP.NET GridView 界面就完成了。希望能帮到你!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值