【风马一族_Android】Android 前端内容

Android 前端内容 

 

4.1 View 类概述

  4.1.1 关于 View

    //类型说明

    view(视图)指的是用户界面组件的基本构建基块。一个视图占据屏幕上的矩形区域,负责绘图和事件处理。视图是基类的小部件,用来创建交互式用户界面组件 (如按钮、 文本字段等)。

    //参数提供

    

属性

方法

说明

适用控件(没有给出,则通用)

Android:background

setBackgroundResource(int)

设置背景

 

Android:clickable

setClickable(boolean)

设置View是否响应单击事件

 

Android:visible

setVisible(int)

控制View的可见性

 

Android:focusable

setFocusable(boolean)

控制View是否可以获取焦点

 

Android:id

setId(int)

为View设置标识符,可通过findViewById()方法获取

 

Anroid:longClickable

setLongClickable(boolean)

设置View是否响应长单击事件

 

Android:saveEnabled

setSaveEnabled(boolean)

如果未作设置,当View被冻结时将不会保存其状态

 

android: orientation

 

设置线性布局的排列方向。Horizontal表示横向,vertical表示纵向

线性布局

android: gravity

 

设置线性布局内部显示对象的位置对齐布局方式(文本居左、居中、居右等等)

 

android: layout_width

 

设置宽度 match_parent 表示填充整个屏幕,wrap_content表示按对象上的文字的宽度不同而确定显示对象的宽度

 

android: layout_height

 

设置高度 match_parent表示填充整个屏幕,wrap_content表示按对象上的文字的宽度不同而确定显示对象的宽度

 

android: layout_weight

 

设置布局内部多个显示对象的重要度赋值,按比例为它们划分空间

线性布局

       
       

  4.1.2 关于 ViewGroup

    //类型说明

 

    //参数提供

4.2 布局

  4.2.1 相对布局 RelativeLayout

    //类型说明

    

    //参数提供

    

    //代码化说明

    

 1 xmlns:android="http://schemas.android.com/apk/res/android"
 2 xmlns:tools="http://schemas.android.com/tools"
 3 //上面是XML用来解决名字冲突的问题而出现的。其专业化称呼就是命名空间
 4 //命名空间的根本要求就是,命名必须是唯一
 5 //网址在世界上是唯一的,因而,被用来当命名空间的名称
 6 //这里的 android 、 tools 只是个变量,后面会经常使用到android
 7 
 8 android:layout_width="match_parent"
 9 android:layout_height="match_parent"
10 //设置布局的高度与宽度。
11 tools:context="cn.com.sgmsc.Relative.Activity_RelativeLayoutActivity"
12 //这行代码是用户获取,界面即见即所得的效果
相对布局的参数说明

 

 

    //完整代码举例

    

 1 import android.support.v7.app.AppCompatActivity;
 2 import android.os.Bundle;
 3 import android.view.View;
 4 import android.widget.EditText;
 5 import android.widget.Toast;
 6 
 7 public class Activity_RelativeLayoutActivity extends AppCompatActivity {
 8 
 9     private EditText editText;
10 
11     @Override
12     protected void onCreate(Bundle savedInstanceState) {
13         super.onCreate(savedInstanceState);
14         setContentView(R.layout.main);
15 
16         editText = (EditText) findViewById(R.id.entry);
17     }
18 
19     public void onClick(View view){
20         switch (view.getId()){
21             case R.id.Ok:
22                 Toast.makeText(this,"输入的数据:"+editText.getText(),Toast.LENGTH_SHORT).show();
23                 break;
24             case R.id.Cancel:
25                     if(editText.getText().length()>0)
26                         Toast.makeText(this,"删除数据",Toast.LENGTH_SHORT).show();
27                     else
28                         Toast.makeText(this,"没有数据",Toast.LENGTH_SHORT).show();
29                 editText.setText("");
30                 break;
31             default:
32                 break;
33         }
34     }
35 }
Activity_RelativeLayoutActivity.java

 

 

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout
 3     xmlns:android="http://schemas.android.com/apk/res/android"
 4     xmlns:tools="http://schemas.android.com/tools"
 5     android:layout_width="match_parent"
 6     android:layout_height="match_parent"
 7     tools:context="cn.com.sgmsc.Relative.Activity_RelativeLayoutActivity">
 8 
 9     <TextView
10         android:id="@+id/label"
11         android:layout_width="match_parent"
12         android:layout_height="wrap_content"
13         android:text="在此处输入:"        />
14     
15     <EditText
16         android:id="@+id/entry"
17         android:layout_width="match_parent"
18         android:layout_height="wrap_content"
19         android:background="@android:drawable/editbox_background"
20         android:layout_below="@id/label"/>
21     <Button
22         android:id="@+id/Ok"
23         android:layout_width="wrap_content"
24         android:layout_height="wrap_content"
25         android:onClick="onClick"
26         android:layout_below="@id/entry"
27         android:layout_alignParentRight="true"
28         android:layout_marginLeft="10dip"
29         android:text="确定" />
30     <Button
31         android:id="@+id/Cancel"
32         android:layout_width="wrap_content"
33         android:layout_height="wrap_content"
34         android:onClick="onClick"
35         android:layout_toLeftOf="@id/Ok"
36         android:layout_alignTop="@id/Ok"
37         android:text="删除" />
38 </RelativeLayout>
main.xml

 

  4.2.2 线性布局 LinearLayout

  4.2.3 表格布局 TableLayout

  4.2.4 帧布局 FrameLayout

  4.2.5 绝对布局 AbsoluteLayout

4.3 组件

  4.3.1 显示文本(TextView)与 显示图片(ImageView)

  4.3.2 编辑文本框 EditView

  4.3.3 按钮 Button 与 图片按钮 (ImageButton)

  4.3.4 单选按钮(CheckBox)与 多选按钮 (RadioButton)

  4.3.5 模拟时钟(AnalogClock)与 数字时钟 (DigitalClock)

  4.3.6 日期选择(DatePicker)与 时间选择 (TimePicker)

4.4 UI设计案例

  4.4.1 计算器界面

  4.4.2 掌上微博

4.5 总结

4.6 题目

4.7 设计类读物

4.8 汉英语对照表

  

  

  

  

posted @ 2015-11-29 22:51  风马一族  阅读(173)  评论(0)    收藏  举报