您好,欢迎访问一九零五行业门户网

【Android】第5章(1)常用基本控件--本章示例主界面

分类:c#、android、vs2015; 创建日期:2016-02-06 这一章主要介绍android简单控件的基本用法。本章源程序共有9个示例,这些示例都在同一个项目中。 项目名:ch05demos,项目模板:blank app(android) 运行主界面截图如下: 点击每行的示例项,即进入对应示
分类:c#、android、vs2015;
创建日期:2016-02-06
这一章主要介绍android简单控件的基本用法。本章源程序共有9个示例,这些示例都在同一个项目中。
项目名:ch05demos,项目模板:blank app(android)
运行主界面截图如下:
点击每行的示例项,即进入对应示例的页面。
1、在drawable文件夹下添加图片添加的图片见下面的左图,也可以直接拖放图片到drawable文件夹下。
右图是各节例子实现后的纵向屏幕布局文件(layout文件夹)、横向屏幕布局文件(layout-land文件夹)、弹出菜单布局文件(menu文件夹)。这些都是在本章后续将要介绍的节中添加的。
2、主界面(main.axml)修改后的代码如下:
xml version=1.0 encoding=utf-8?>linearlayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:layout_width=fill_parent android:layout_height=fill_parent> listview android:minwidth=25px android:minheight=25px android:layout_width=match_parent android:layout_height=match_parent android:id=@+id/listview1 />linearlayout>
3、主界面对应的活动文件(mainactivity.cs)本章示例全部完成后mainactivity.cs的代码如下:
using system;using android.app;using android.widget;using android.os;using ch05demos.srcactivity;namespace ch05demos{ [activity(label = ch05demos, mainlauncher = true, icon = @drawable/icon)] public class mainactivity : activity { string[] items; protected override void oncreate(bundle bundle) { base.oncreate(bundle); setcontentview(resource.layout.main); items = new string[] { demo01edittext, demo02login, demo03multiresolution, demo04checkboxradiobutton, demo05spinner, demo06switchandratingbar, demo07popupmenu, demo08gallery, demo09seekbar }; listview listview1 = findviewbyid(resource.id.listview1); listview1.adapter = new arrayadapterstring>(this, android.resource.layout.simplelistitem1, items); listview1.itemclick += (s, e) => { int index = e.position + 1; switch(index) { case 1: startactivity(typeof(demo01edittext)); break; case 2: startactivity(typeof(demo02login)); break; case 3: startactivity(typeof(demo03multiresolution)); break; case 4: startactivity(typeof(demo04checkboxradiobutton)); break; case 5: startactivity(typeof(demo05spinner)); break; case 6: startactivity(typeof(demo06switchandratingbar)); break; case 7: startactivity(typeof(demo07popupmenu)); break; case 8: startactivity(typeof(demo08gallery)); break; case 9: startactivity(typeof(demo09seekbar)); break; } }; } }}
4、清单文件(androidmanifest.xml)在这个文件中只添加了一条内容:设置应用到所有页面的公用主题。
xml version=1.0 encoding=utf-8?>manifest xmlns:android=http://schemas.android.com/apk/res/android package=ch05demos.ch05demos android:versioncode=1 android:versionname=1.0> uses-sdk /> application android:label=ch05demos android:theme=@android:style/theme.devicedefault.light>application>manifest>
从下一节开始,将分别介绍如何实现各个示例,以及这些示例涉及的相关概念。
其它类似信息

推荐信息