Android界面开发之常用系统控件界面大合集

Android界面开发之常用系统控件界面大合集
Android界面开发之常用系统控件界面大合集

今天我用自己写的一个Demo 和大家详细介绍一个Android开发中遇到的一些常用系统控件的使用技巧。

1.文本框TextView

TextView的作用是用来显示一个文本框,下面我用两种方式为大家呈现TextView,第一种是通过xml布局文件

呈现,第二种是通过代码来呈现,由此可见Android 的界面开发真的是非常灵活。

view plaincopy to clipboardprint?

1. public class TextViewActivity extends Activity {

2. @Override

3. protected void onCreate(Bundle savedInstanceState) {

4. setContentView(https://www.360docs.net/doc/0717303485.html,yout.textview);

5.

6. LinearLayout ll = (LinearLayout) findViewById(R.id.textviewll);

7. TextView textView = new TextView(this);

8. //设置显示文字

9. textView.setText("从代码中添加一个TextView");

10. //设置显示颜色

11. textView.setTextColor(Color.WHITE);

12. //设置显示字体大小

13. textView.setTextSize(18);

14. //设置显示背景颜色

15. textView.setBackgroundColor(Color.BLUE);

16. //设置锚点位置

17. textView.setGravity(Gravity.CENTER_VERTICAL|Gravity.CE

NTER_HORIZONTAL);

18. //把这个view加入到布局当中

19. ll.addView(textView);

20.

21. super.onCreate(savedInstanceState);

22. }

23. }

1.

2.

3. android:id="@+id/textviewll"

4. android:orientation="vertical"android:layout_width="fill_parent

"

5. android:layout_height="fill_parent">

6.

7. android:layout_width="fill_parent"

8. android:layout_height="wrap_content"

9. android:textColor="#000000"

10. android:textSize="18dip"

11. android:background="#00FF00"

12. android:text="@string/textView"

13. android:gravity="center_vertical|center_horizontal"

14. />

15.

view plaincopy to clipboardprint?

1. public class WebViewActivity extends Activity {

2. WebView webView = null;

3. static final String MIME_TYPE = "text/html";

4. static final String ENCODING = "utf-8";

5.

6.

7. @Override

8. protected void onCreate(Bundle savedInstanceState) {

9. setContentView(https://www.360docs.net/doc/0717303485.html,yout.webview);

10.

11. webView = (WebView) findViewById(R.id.webview);

12. webView.loadDataWithBaseURL(null,"欢迎访问雨松MOMO的博客

", MIME_TYPE, ENCODING, null);

13. super.onCreate(savedInstanceState);

14. }

15. }

1.

2.

3. android:id="@+id/textviewll"

4. android:orientation="vertical"android:layout_width="fill_parent

"

5. android:layout_height="fill_parent">

6.

7. android:layout_height="wrap_content"

8. android:textColor="#000000"

9. android:textSize="18dip"

10. android:background="#00FF00"

11. android:text="网页框WebView测试"

12. android:gravity="center_vertical|center_horizontal"

13. />

14.

15. android:layout_height="wrap_content"

16. android:layout_width="fill_parent"/>

17.

view plaincopy to clipboardprint?

1. public class MenuActivity extends Activity {

2.

3. @Override

4. protected void onCreate(Bundle savedInstanceState) {

5. setContentView(https://www.360docs.net/doc/0717303485.html,yout.menuview);

6. super.onCreate(savedInstanceState);

7. }

8.

9. @Override

10. public boolean onCreateOptionsMenu(Menu menu) {

11. menu.add(0, 0, Menu.NONE, "菜单

1").setIcon(R.drawable.icon);

12. menu.add(0, 1, Menu.NONE, "菜单

2").setIcon(R.drawable.icon);

13. menu.add(0, 2, Menu.NONE, "菜单

3").setIcon(R.drawable.icon);

14. menu.add(0, 3, Menu.NONE, "菜单

4").setIcon(R.drawable.icon);

15. menu.add(0, 4, Menu.NONE, "菜单

5").setIcon(R.drawable.icon);

16. menu.add(0, 5, Menu.NONE, "菜单

6").setIcon(R.drawable.icon);

17. return super.onCreateOptionsMenu(menu);

18. }

19.

20. @Override

21. public boolean onOptionsItemSelected(MenuItem item) {

22. Dialog(item.getItemId());

23. return super.onOptionsItemSelected(item);

24. }

25.

26. private void Dialog(int message) {

27. new AlertDialog.Builder(this).setMessage(

28. "您单击第【" + message + "】项Menu菜单项.").show();

29. }

30. }

1.

2.

3. android:orientation="vertical"android:layout_width="fill_parent

"

4. android:layout_height="fill_parent">

5.

6. android:layout_height="wrap_content"

7. android:textColor="#000000"

8. android:textSize="18dip"

9. android:background="#00FF00"

10. android:text="Menu菜单测试"

11. android:gravity="center_vertical|center_horizontal"

12. />

13.

view plaincopy to clipboardprint?

1. public class ButtonActivity extends Activity {

2.

3. Context mContext = null;

4. @Override

5. protected void onCreate(Bundle savedInstanceState) {

6. setContentView(https://www.360docs.net/doc/0717303485.html,yout.buttonview);

7. mContext = this;

8.

9. //普通按钮

10. Button button0 = (Button)findViewById(R.id.buttonview0);

12. //设置按钮文字颜色

13. button0.setTextColor(Color.BLUE);

14. //设置按钮文字大小

15. button0.setTextSize(30);

16.

17. //设置按钮监听点击事件

18. button0.setOnClickListener(new OnClickListener() {

19.

20. @Override

21. public void onClick(View arg0) {

22. Toast.makeText(ButtonActivity.this, "您点击了‘这是一个按

钮’", Toast.LENGTH_LONG).show();

23.

24. }

25. });

26.

27. //带图片的按钮

28. ImageButton button1 = (ImageButton)findViewById(R.id.butto

nview1);

29. //设置按钮监听点击事件

30. button1.setOnClickListener(new OnClickListener() {

31.

32. @Override

33. public void onClick(View arg0) {

34. Toast.makeText(ButtonActivity.this, "您点击了一个带图片的

按钮", Toast.LENGTH_LONG).show();

35.

36. }

37. });

38. super.onCreate(savedInstanceState);

39. }

1.

2.

3. android:orientation="vertical"android:layout_width="fill_parent

"

4. android:layout_height="fill_parent">

5.

6. android:layout_height="wrap_content"

7. android:textColor="#000000"

8. android:textSize="18dip"

9. android:background="#00FF00"

10. android:text="Button按钮测试"

11. android:gravity="center_vertical|center_horizontal"

12. />

13.

14. android:id="@+id/buttonview0"

15. android:layout_width="fill_parent"

16. android:layout_height="wrap_content"

17. android:text="这是一个按钮"

18. />

19.

20. android:id="@+id/buttonview1"

21. android:layout_width="fill_parent"

22. android:layout_height="wrap_content"

23. android:src="@drawable/icon"

24. />

25.

view plaincopy to clipboardprint?

1. public class EditTextActivity extends Activity {

2.

3. Context mContext = null;

4. @Override

5. protected void onCreate(Bundle savedInstanceState) {

6. setContentView(https://www.360docs.net/doc/0717303485.html,yout.editview);

7. mContext = this;

8. //帐号

9. final EditText editText0 = (EditText)findViewById(R.id.editview

0);

10. //密码

11. final EditText editText1 = (EditText)findViewById(R.id.editview

1);

12.

13. //确认按钮

14. Button button = (Button)findViewById(R.id.editbutton0);

15.

16. button.setOnClickListener(new OnClickListener() {

17.

18. @Override

19. public void onClick(View arg0) {

20. String username = editText0.getText().toString();

21. String password = editText1.getText().toString();

22. Toast.makeText(EditTextActivity.this, "用户名:

"+username +"密码:

"+ password, Toast.LENGTH_LONG).show();

23. }

24. });

25. super.onCreate(savedInstanceState);

26. }

27. }

1.

2.

3. android:orientation="vertical"android:layout_width="fill_parent

"

4. android:layout_height="fill_parent">

5.

6. android:layout_height="wrap_content"

7. android:textColor="#000000"

8. android:textSize="18dip"

9. android:background="#00FF00"

10. android:text="EditText编辑框测试"

11. android:gravity="center_vertical|center_horizontal"

12. />

13.

14. android:id="@+id/editview0"

15. android:layout_width="fill_parent"

16. android:layout_height="wrap_content"

17. android:hint="请输入帐号"

18. android:phoneNumber="true"

19. />

20.

21.

22. android:id="@+id/editview1"

23. android:layout_width="fill_parent"

24. android:layout_height="wrap_content"

25. android:hint="请输入密码"

26. android:password="true"

27. />

28.

29. android:id="@+id/editbutton0"

30. android:layout_width="fill_parent"

31. android:layout_height="wrap_content"

32. android:text="确定"

33. />

34.

view plaincopy to clipboardprint?

1. public class RadioActivity extends Activity {

2.

3. Context mContext = null;

4. @Override

5. protected void onCreate(Bundle savedInstanceState) {

6. setContentView(https://www.360docs.net/doc/0717303485.html,yout.radioview);

7. mContext = this;

8. //单选组(只有在一个组中的按钮可以单选)

9. RadioGroup radioGroup = (RadioGroup)findViewById(R.id.rad

ion0);

Android人机界面(UI)设计规范(带目录)

Android 人机界面设计规范 1Android 设计的依据 1.1 框架结构及流程 是什么使得android 有着独特的用户体验? 后台处理支持多任务功能 正在进行和事件驱动的提示信息 通过Widgets 和live folders 来实现实时信息的预览 用户想用时,任一应用程序都可以挑选和选择 android 不是关于程序的,它是关于活动,把任务分层, 1.2 架构基础 硬件平台 android 设备代表的是硬件和软件的完美组合。硬件辅助导航操作,并给android 提供更多更好的功能。当菜单没有开启,要把屏幕最大化时,菜单按钮可以在屏幕上提供更多的内容。返回按钮允许使用返回堆(back stack)。 竖屏与横屏 一般来说,用户界面开发竖屏与横屏。在新横屏也仍存在于新的Android 手机中。99%的android 布局支持横屏。 焦点和菜单 在触摸模式里没有焦点,只有轨迹球。Android 平台里没有鼠标焦点。确定你从未显示焦点。主菜单应该包括全部功能;它们与活动联系一起形成整体。菜单上的图标按重要性排序。如果有多于5 个图标,使用点击more menu 菜单来查看那些不太重要的菜单项。上下文菜单(长按)集中在一个特定对象。 总是把那些与所选项最相关的行为放在长按菜单的顶部。 需要记住的几点: 设计时要考虑速度和简洁 尽量分层来分等级 屏幕上的活动尽量最小 使用下载进度条,下载数据时,而不是让用户等待去看一个加载完全的页面。 考虑活动流而不是线性行为 1.3 屏幕上的行为

android 设计了特定的行为方式。在你的应用程序里利用好这一点。应该坚持android 行为的标准,避免混淆用户。 1.4 表达 细节使得产品集中在细节。程序的美学会帮助你集中注意在那些应用体验核心的关键任务上。API DEMO 是开始你的工具包的好地方。 2 用户界面原则 这部分试图讲述创造一个好的用户界面的一些基本的交互设计原则。这些原则是基本的,不止能应用于android 的用户界面设计,也可以应用于其他。苹果建议开发者花费60%的开发时间来进行设计工作。下面的用户界面原则将为好的设计提供一个基础。 2.1 隐喻 隐喻是构建一个基于操作任务心智模型的模块;用它们来传递应用程序的概念和功能。基于真实世界的应用对象可以帮助用户很快的理解该应用程序。当你设计你的应用程序时,要注意andriod 中存在的隐喻,不要重新定义它们。同时,检查你的应用程序执行的任务,看是否有些自然隐喻你可以使用。 2.2 反映用户的心智模型 用户已经有了一个来描述你的程序正在进行的任务的心智模型。这个心智模型产生于真实世界经验、其它软件和一般电脑基本知识的结合。比如说,用户在真实世界里有写字、寄信的经验,也会产生特定的期待,像写一封新的信,选一个接受者,然后寄出信。一个忽略用户心智模型的电子邮件程序用起来会很困难和不舒服。这是因为程序强加给用户一个不熟悉的概念模型,而不是建立一个用户已有的知识经验模式。 在设计程序用户界面之前,试着去发现你的用户的心智模型,这样帮助用户去执行任务。心智模型中内在的隐喻,它代表了任务的概念组成。在写信这个例子中,隐喻包括信件、邮包和信封。在涉及到照片的任务的思考模式中,隐喻包括照片、照相机和专辑。我们要努力地发现用户的期望,包括任务组成、组织、窗口布局的工作流、菜单和工具栏组织、控制面板的使用。 要通过努力地何必把个下面的特征与用户心智模型相融合: 熟悉性 用户的心智模型主要是建立在经验的基础上 简单化 一项任务的心智模型通常是流线型,关注任务的基本组成部分。尽管对于一个给定的任务有很多可选的细节,但是基本的组成部分占大部分,并且不会占用用户的注意。 可利用性Availability

android studio 控件常用属性

android studio 控件常用属性 下面是RelativeLayout各个属性 1.android:layout_above="@id/xxx" --将控件置于给定ID控件之上 2.android:layout_below="@id/xxx" --将控件置于给定ID控件之下 3. android:layout_toLeftOf="@id/xxx" --将控件的右边缘和给定ID控件的左边缘对齐 4.android:layout_toRightOf="@id/xxx" --将控件的左边缘和给定ID控件的右边缘对齐 5. android:layout_alignLeft="@id/xxx" --将控件的左边缘和给定ID控件的左边缘对齐 6.android:layout_alignTop="@id/xxx" --将控件的上边缘和给定ID控件的上边缘对齐 7.android:layout_alignRight="@id/xxx" --将控件的右边缘和给定ID控件的右边缘对齐 8.android:layout_alignBottom="@id/xxx" --将控件的底边缘和给定ID控件的底边缘对齐 9.android:layout_alignParentLeft="true" --将控件的左边缘和父控件的左边缘对齐 10. android:layout_alignParentTop="true" --将控件的上边缘和父控件的上边缘对齐 11. android:layout_alignParentRight="true" --将控件的右边缘和父控件的右边缘对齐 12.android:layout_alignParentBottom="true" --将控件的底边缘和父控件的底边缘对齐 13.android:layout_centerInParent="true" --将控件置于父控件的中心位置 14.android:layout_centerHorizontal="true" --将控件置于水平方向的中心位置 15.android:layout_centerVertical="true" --将控件置于垂直方向的中心位置 android:layout_width 设置组件的宽度 android:layout_height 设置组件的高度 android:id 给组件定义一个id值,供后期使用 android:background 设置组件的背景颜色或背景图片 android:text 设置组件的显示文字 android:textColor 设置组件的显示文字的颜色 android:layout_below 组件在参考组件的下面 android:alignTop 同指定组件的顶平行

Android简单的登陆界面的设计开发

通信实训报告 -Android移动平台开发 学院:信息工程学院 班级: 学号: 姓名:

实训内容: 一.1.Andriod的简介 Android一词的本义指“机器人”,同时也是Google于2007年11月5日宣布的基于Linux平台的开源手机操作系统的名称,该平台由操作系统、中间件、用户界面和应用软件组成,号称是首个为移动终端打造的真正开放和完整的移动软件。目前,最新版本为Android 2.4 Gingerbread 和Android 3.0 Honeycomb。 Android是基于Linux开放性内核的操作系统,是Google公司在2007年11月5日公布的手机操作系统。 Android早期由原名为"Android"的公司开发,谷歌在2005年收购"Android.Inc"后,继续对Android系统开发运营,它采用了软件堆层(software stack,又名软件叠层)的架构,主要分为三部分。底层Linux内核只提供基本功能,其他的应用软件则由各公司自行开发,部分程序以Java编写。2011年初数据显示,仅正式上市两年的操作系统Android已经超越称霸十年的塞班系统,使之跃居全球最受欢迎的智能手机平台。现在,Android系统不但应用于智能手机,也在平板电脑市场急速扩张,在智能MP4方面也有较大发展。采用Android系统主要厂商包括台湾的HTC,(第一台谷歌的手机G1由HTC生产代工)美国摩托罗拉,SE等,中国大陆厂商如:魅族(M9),华为、中兴、联想、蓝魔等。 2.Android构架图 二.1软件下载 Android SDK,网址是https://www.360docs.net/doc/0717303485.html,. JDK的下载地址https://www.360docs.net/doc/0717303485.html,/javase/downloads/widget/jdk6.jsp。Eclipse的下载网址是https://www.360docs.net/doc/0717303485.html,/downloads/ 2.Android开发环境搭建

Android常用控件

《Android基础应用》 Android常用控件 ?本章任务 ?使用Android开发使用时间组件 ?使用Android开发使用进度条组件 ?使用Android开发创建底部选项卡 ?本章目标 ?了解Android的组件层次结构 ?掌握常用的日期时间类控件 ?掌握常用的几个容器组件 1.Android组件的层次结构 UI组件都是View的子类,View有很多子类,它们之间存在树状的继承关系View及其子类结构图

TextView及其子类结构图

ViewGroup及其子类结构图 其下的子类一般作为容器或布局来使用 FrameLayout及其子类结构图 其下的子类通常作为容器或布局来使用

2.时间控件 2.1日期时间选择器 DatePicker组件可用于输入日期,TimePicker组件可用来选择时间,只能输入小时和分,默认12小时制 DatePicker ●使用onDateChangedListener监听器来获取用户的日期选择 ●使用init对组件进行初始化 ●使用getYear,getMonth,getDayOfMonth方法获得用户选择的年,月,日 TimePicker ●使用onTimeChangedListener监听器获取用户的时间选择 ●使用setIs24HourView设置是否以24小时制显示 ●使用getCurrentHour获得当前的小时数 ●使用getCurrentMinute获得当前的分钟数 示例

示例的实现结果

2.2时钟组件 AnalogClock组件用来以表盘的方式显示当前时间,该表只有时针和分针,DigitClock组件以数字的方式显示当前时间可以显示时分秒,由于DigitClock继承TextView,可以使用TextView 的属性 示例

Android界面开发之常用系统控件界面大合集

今天我用自己写的一个Demo 和大家详细介绍一个Android开发中遇到的一些常用系统控件的使用技巧。 1.文本框TextView TextView的作用是用来显示一个文本框,下面我用两种方式为大家呈现TextView,第一种是通过xml布局文件

呈现,第二种是通过代码来呈现,由此可见Android 的界面开发真的是非常灵活。 view plaincopy to clipboardprint? 1. public class TextViewActivity extends Activity { 2. @Override 3. protected void onCreate(Bundle savedInstanceState) { 4. setContentView(https://www.360docs.net/doc/0717303485.html,yout.textview);

5. 6. LinearLayout ll = (LinearLayout) findViewById(R.id.textviewll); 7. TextView textView = new TextView(this); 8. //设置显示文字 9. textView.setText("从代码中添加一个TextView"); 10. //设置显示颜色 11. textView.setTextColor(Color.WHITE); 12. //设置显示字体大小 13. textView.setTextSize(18); 14. //设置显示背景颜色 15. textView.setBackgroundColor(Color.BLUE); 16. //设置锚点位置 17. textView.setGravity(Gravity.CENTER_VERTICAL|Gravity.CE NTER_HORIZONTAL); 18. //把这个view加入到布局当中 19. ll.addView(textView); 20. 21. super.onCreate(savedInstanceState); 22. } 23. } 1. 2.

第四章Android用户界面

第四章Android用户界面 P3 Android系统为我们提供了丰富的可视化用户界面组件,包括菜单、对话框、按钮、下列列表等。Android系统借用了Java里的UI设计思想,包括事件响应机制和布局管理,所以有过Java UI开发经验的学生,学些这一章会很轻松。 Android系统中所有UI类都是建立在View和ViewGroup这两个类的基础之上的。所有View 的子类称为Widget,所有ViewGroup的子类称为Layout。 P5 View和ViewGroup之间采用了组合设计模式(Composite)。 P6 ViewGroup作为布局容器类在最上层,布局容器里面又可以有View和ViewGroup。 P16 为了更好地管理Android应用的用户界面里的各组件,Android提供了布局管理器。通过使用布局管理器,Android应用的图形用户界面具有良好的平台无关性。通常来说,推荐使用布局管理器来管理组件的分布、大小,而不是直接设置组件的位置和大小。这样可以让组件在不同的手机屏幕上都能运行良好—不同手机屏幕的分辨率、尺寸并不完全相同。如果让程序手动控制每个组件的大小、位置、则将给编程带来巨大的困难。为了解决这个问题,Android 提供了布局管理器。布局管理器可以根据运行平台来调整组件的大小,程序员要做的,只是为组件选择合适的布局管理器。 与Swing不同的是,Android的布局管理器本身就是一个UI组件,所有布局管理器都是ViewGroup的子类。 P18 线性布局由LinearLayout来代表,线性布局有点像AWT编程里的FlowLayout,他们都会将容器里的组件一个挨着一个地排列起来。LinearLayout不仅可以控制组件横向排列,也可控制各组件纵向排列。 线性布局与AWT中的FlowLayout的最大区别在于:Android的线性布局不会换行:当组件一个挨着一个地排列到头后,剩下的组件将不会被现实出来;在AWT中FlowLayout则会另起一行排列多出来的组件。

第4章 Android用户界面设计

视图组件的使用模式 常用组件 高级组件 提示框与警告对话框

就是Android应用程序的开发过程。一般过程是先通过XML布局文件或Java代码创建界面布局,设定组件显示样式,随后获取UI组件对象,并处理组件事件响应。 视图组件的定义 资源的访问 生成视图组件资源标识 视图组件的引用 视图组件的事件响应 组件的常用属性

1.1视图组件的定义 使用XML布局文件定义视图组件 使用Java代码定义视图组件(不推荐)

1.1视图组件的定义 使用XML布局文件定义视图组件 Android平台为大多数视图组件以及其子类提供了XML标记,可通过XML布局文件中的标记来定义视图组件。XML中的每个元素代表了一个组件,即元素名称对应相应的Java类。

1.1视图组件的定义

相关文档
最新文档