uiControl整体界面如下图所示,按照视频教程,学习控件由于是初学,都是最基础知识。还有ImageSwitcher、Gallery未更新,o(╯□╰)o

 1 package com.example.uiconrrol;
2
3 import android.content.Context;
4 import android.content.Intent;
5
6 public class ListCellData {
7
8 public ListCellData(Context context, String controlName,
9 Intent relatedIntent) {
10 this.controlName = controlName;
11 this.context = context;
12 this.relatedIntent = relatedIntent;
13 }
14
15 private String controlName = "";
16
17 public String getControlName() {
18 return controlName;
19 }
20
21 private Context context = null;
22
23 public Context getContext() {
24 return context;
25 }
26
27 private Intent relatedIntent = null;
28
29 public Intent getRelatedIntent() {
30 return relatedIntent;
31 }
32
33 public void startActivity() {
34 getContext().startActivity(getRelatedIntent());
35 }
36
37 // 重写toString方法,只显示Name
38 @Override
39 public String toString() {
40 return getControlName();
41 }
42
43 }

ListCellData

 1 package com.example.uiconrrol;
2
3 import android.app.ListActivity;
4 import android.content.Intent;
5 import android.os.Bundle;
6 import android.view.View;
7 import android.widget.ArrayAdapter;
8 import android.widget.ListView;
9
10 public class MainActivity extends ListActivity {
11
12 private ArrayAdapter<ListCellData> adapter;
13
14 @Override
15 protected void onCreate(Bundle savedInstanceState) {
16 super.onCreate(savedInstanceState);
17
18 adapter = new ArrayAdapter<ListCellData>(this,
19 android.R.layout.simple_list_item_1);
20 setListAdapter(adapter);
21
22 adapter.add(new ListCellData(this, "RadioGroup", new Intent(this,
23 AtyUsingRadioGroup.class)));
24 adapter.add(new ListCellData(this, "CheckBox", new Intent(this,
25 AtyUsingCheckBox.class)));
26 adapter.add(new ListCellData(this, "DatePicker", new Intent(this,
27 AtyUsingDatePicker.class)));
28 adapter.add(new ListCellData(this, "TimePicker", new Intent(this,
29 AtyUsingTimePicker.class)));
30 adapter.add(new ListCellData(this, "Spinner", new Intent(this,
31 AtyUsingSpinner.class)));
32 adapter.add(new ListCellData(this, "ProgressBar", new Intent(this,
33 AtyUsingProgressBar.class)));
34 adapter.add(new ListCellData(this, "SeekBar", new Intent(this,
35 AtyUsingSeekBar.class)));
36 adapter.add(new ListCellData(this, "GridView", new Intent(this,
37 AtyUsingGridView.class)));
38 adapter.add(new ListCellData(this, "ProgressDialog", new Intent(this,
39 AtyUsingProgressDialog.class)));
40 adapter.add(new ListCellData(this, "Notification", new Intent(this,
41 AtyUsingNotification.class)));
42 adapter.add(new ListCellData(this, "SrcollView", new Intent(this,
43 AtyUsingSrcollView.class)));
44 adapter.add(new ListCellData(this, "RatingBar", new Intent(this,
45 AtyUsingRatingBar.class)));
46 }
47
48 @Override
49 protected void onListItemClick(ListView l, View v, int position, long id) {
50
51 ListCellData data = adapter.getItem(position);
52 data.startActivity();
53
54 super.onListItemClick(l, v, position, id);
55 }
56
57 }

MainActivity

 1 <?xml version="1.0" encoding="utf-8"?>
2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3 package="com.example.uiconrrol"
4 android:versionCode="1"
5 android:versionName="1.0" >
6
7 <uses-sdk
8 android:minSdkVersion="8"
9 android:targetSdkVersion="21" />
10
11 <application
12 android:allowBackup="true"
13 android:icon="@drawable/ic_launcher"
14 android:label="@string/app_name"
15 android:theme="@style/AppTheme" >
16 <activity
17 android:name=".MainActivity"
18 android:label="@string/app_name" >
19 <intent-filter>
20 <action android:name="android.intent.action.MAIN" />
21
22 <category android:name="android.intent.category.LAUNCHER" />
23 </intent-filter>
24 </activity>
25 <activity android:name="AtyUsingRadioGroup" >
26 </activity>
27 <activity android:name="AtyUsingCheckBox" >
28 </activity>
29 <activity android:name="AtyUsingDatePicker" >
30 </activity>
31 <activity android:name="AtyUsingTimePicker" >
32 </activity>
33 <activity android:name="AtyUsingSpinner" >
34 </activity>
35 <activity android:name="AtyUsingProgressBar" >
36 </activity>
37 <activity android:name="AtyUsingSeekBar" >
38 </activity>
39 <activity android:name="AtyUsingGridView" >
40 </activity>
41 <activity android:name="AtyUsingProgressDialog" >
42 </activity>
43 <activity android:name="AtyUsingNotification" >
44 </activity>
45 <activity android:name="AtyUsingSrcollView" >
46 </activity>
47 <activity android:name="AtyUsingRatingBar" >
48 </activity>
49 </application>
50
51 </manifest>

AndroidManifest.xml

1. RadioGroup

  介绍Android中如何使用RadioGroup和RadioButton,实现自定义的RadioGroup中被选中RadioButton的变更监听事件。

 1 package com.example.uiconrrol;
2
3 import android.app.Activity;
4 import android.app.AlertDialog;
5 import android.os.Bundle;
6 import android.view.View;
7 import android.widget.RadioButton;
8
9 public class AtyUsingRadioGroup extends Activity {
10
11 private RadioButton radioRight;
12
13 @Override
14 protected void onCreate(Bundle savedInstanceState) {
15 // TODO Auto-generated method stub
16 super.onCreate(savedInstanceState);
17 setContentView(R.layout.aty_using_radiogroup);
18
19 radioRight = (RadioButton) findViewById(R.id.radioRight);
20
21 findViewById(R.id.btnSubmit).setOnClickListener(
22 new View.OnClickListener() {
23
24 @Override
25 public void onClick(View v) {
26 if (radioRight.isChecked()) {
27 new AlertDialog.Builder(AtyUsingRadioGroup.this)
28 .setTitle("判断").setMessage("回答正确")
29 .setPositiveButton("Cancel", null).show();
30 } else {
31 new AlertDialog.Builder(AtyUsingRadioGroup.this)
32 .setTitle("判断").setMessage("回答错误")
33 .setPositiveButton("Cancel", null).show();
34 }
35 }
36 });
37 }
38 }

AtyUsingRadioGroup

 1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 android:orientation="vertical" >
6
7 <TextView
8 android:id="@+id/textView1"
9 android:layout_width="wrap_content"
10 android:layout_height="wrap_content"
11 android:text="老师是个帅哥吗?" />
12
13 <RadioGroup
14 android:id="@+id/radioGroup1"
15 android:layout_width="wrap_content"
16 android:layout_height="wrap_content" >
17
18 <RadioButton
19 android:id="@+id/radioRight"
20 android:layout_width="wrap_content"
21 android:layout_height="wrap_content"
22 android:text="是" />
23
24 <RadioButton
25 android:id="@+id/radioNo"
26 android:layout_width="wrap_content"
27 android:layout_height="wrap_content"
28 android:text="不是" />
29
30 <RadioButton
31 android:id="@+id/radio2"
32 android:layout_width="wrap_content"
33 android:layout_height="wrap_content"
34 android:text="不知道" />
35 </RadioGroup>
36
37 <Button
38 android:id="@+id/btnSubmit"
39 android:layout_width="wrap_content"
40 android:layout_height="wrap_content"
41 android:text="提交" />
42
43 </LinearLayout>

aty_using_radiogroup.xml

2. CheckBox

  CheckBox是多项选择,允许用户用列表中选择一个或多个选项,它在android源代码中是继承CompoundButton类的,而CompoundButton类是继承于Button类的。

 1 package com.example.uiconrrol;
2
3 import android.app.Activity;
4 import android.app.AlertDialog;
5 import android.os.Bundle;
6 import android.view.View;
7 import android.widget.Button;
8 import android.widget.CheckBox;
9
10 public class AtyUsingCheckBox extends Activity {
11
12 private CheckBox cbMifan, cbDoufu, cbXihongshi, cbTudou;
13 private Button btnSubmit;
14
15 @Override
16 protected void onCreate(Bundle savedInstanceState) {
17 super.onCreate(savedInstanceState);
18 setContentView(R.layout.aty_using_checkbox);
19
20 cbMifan = (CheckBox) findViewById(R.id.cbMifan);
21 cbDoufu = (CheckBox) findViewById(R.id.cbDoufu);
22 cbXihongshi = (CheckBox) findViewById(R.id.cbXihongshi);
23 cbTudou = (CheckBox) findViewById(R.id.cbTudou);
24
25 btnSubmit = (Button) findViewById(R.id.btnSubmit);
26
27 btnSubmit.setOnClickListener(new View.OnClickListener() {
28
29 @Override
30 public void onClick(View v) {
31
32 String str = "中午要吃的是: \n";
33
34 if (cbMifan.isChecked()) {
35 str += "米饭 \n";
36 }
37 if (cbDoufu.isChecked()) {
38 str += "豆腐 \n";
39 }
40 if (cbXihongshi.isChecked()) {
41 str += "西红柿 \n";
42 }
43 if (cbTudou.isChecked()) {
44 str += "土豆";
45 }
46
47 new AlertDialog.Builder(AtyUsingCheckBox.this).setTitle("结果")
48 .setMessage(str).setPositiveButton("关闭", null).show();
49 }
50 });
51 }
52 }

AtyUsingCheckBox

 1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 android:orientation="vertical" >
6
7 <TextView
8 android:id="@+id/textView1"
9 android:layout_width="wrap_content"
10 android:layout_height="wrap_content"
11 android:text="中午你打算吃什么?"
12 android:textAppearance="?android:attr/textAppearanceLarge" />
13
14 <CheckBox
15 android:id="@+id/cbTudou"
16 android:layout_width="wrap_content"
17 android:layout_height="wrap_content"
18 android:text="土豆" />
19
20 <CheckBox
21 android:id="@+id/cbXihongshi"
22 android:layout_width="wrap_content"
23 android:layout_height="wrap_content"
24 android:text="西红柿" />
25
26 <CheckBox
27 android:id="@+id/cbMifan"
28 android:layout_width="wrap_content"
29 android:layout_height="wrap_content"
30 android:text="米饭" />
31
32 <CheckBox
33 android:id="@+id/cbDoufu"
34 android:layout_width="wrap_content"
35 android:layout_height="wrap_content"
36 android:text="豆腐" />
37
38 <Button
39 android:id="@+id/btnSubmit"
40 android:layout_width="wrap_content"
41 android:layout_height="wrap_content"
42 android:text="提交" />
43
44 </LinearLayout>

aty_using_checkbox.xml

3. DatePicker

  DatePicker是一个选择年月日的日历控件。

 1 package com.example.uiconrrol;
2
3 import android.app.Activity;
4 import android.app.DatePickerDialog;
5 import android.os.Bundle;
6 import android.view.View;
7 import android.widget.Button;
8 import android.widget.DatePicker;
9
10 public class AtyUsingDatePicker extends Activity {
11
12 private Button btnDatePicer;
13
14 @Override
15 protected void onCreate(Bundle savedInstanceState) {
16 super.onCreate(savedInstanceState);
17 setContentView(R.layout.aty_using_datepicker);
18
19 btnDatePicer = (Button) findViewById(R.id.btnSelectDate);
20
21 btnDatePicer.setOnClickListener(new View.OnClickListener() {
22
23 @Override
24 public void onClick(View v) {
25 new DatePickerDialog(AtyUsingDatePicker.this,
26 new DatePickerDialog.OnDateSetListener() {
27
28 @Override
29 public void onDateSet(DatePicker view, int year,
30 int monthOfYear, int dayOfMonth) {
31 btnDatePicer.setText(String.format("%d:%d:%d",
32 year, monthOfYear, dayOfMonth));
33 }
34 }, 2014, 10, 22).show();
35 }
36 });
37 }
38 }

AtyUsingDatePicker

 1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 android:orientation="vertical" >
6
7 <Button
8 android:id="@+id/btnSelectDate"
9 android:layout_width="match_parent"
10 android:layout_height="wrap_content"
11 android:text="0000:00:00" />
12
13 </LinearLayout>

aty_using_datepicker.xml

4. TimePicker

  TimePicker也继承自FrameLayout类,时间选择控件向用户显示一天中的时间(可以为24小时,也可以为AM/PM制),并允许用户进行选择,如果要捕获用户修改时间数据的事件,便需要为TimePicker添加 OnTimeChangedListener监听器。

 1 package com.example.uiconrrol;
2
3 import android.app.Activity;
4 import android.app.TimePickerDialog;
5 import android.os.Bundle;
6 import android.view.View;
7 import android.widget.Button;
8 import android.widget.TimePicker;
9
10 public class AtyUsingTimePicker extends Activity {
11
12 private Button btnSelectTime;
13
14 @Override
15 protected void onCreate(Bundle savedInstanceState) {
16 super.onCreate(savedInstanceState);
17 setContentView(R.layout.aty_using_timepicker);
18
19 btnSelectTime = (Button) findViewById(R.id.btnSelectTime);
20
21 btnSelectTime.setOnClickListener(new View.OnClickListener() {
22
23 @Override
24 public void onClick(View v) {
25
26 new TimePickerDialog(AtyUsingTimePicker.this,
27 new TimePickerDialog.OnTimeSetListener() {
28
29 @Override
30 public void onTimeSet(TimePicker view,
31 int hourOfDay, int minute) {
32 btnSelectTime.setText(String.format("%s:%s",
33 timeFormat(hourOfDay),
34 timeFormat(minute)));
35 }
36 }, 10, 25, true).show();
37 }
38 });
39 }
40
41 public String timeFormat(int value) {
42 return (value >= 10) ? ("" + value) : ("0" + value);
43 }
44 }

AtyUsingTimePicker

 1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 android:orientation="vertical" >
6
7 <Button
8 android:id="@+id/btnSelectTime"
9 android:layout_width="wrap_content"
10 android:layout_height="wrap_content"
11 android:text="00:00" />
12
13 </LinearLayout>

aty_using_timepicker.xml

5. Spinner

  Spinner位于android.widget包下,每次只显示用户选中的元素,当用户再次点击时,会弹出选择列表供用户选择,而选择列表中的元素同样来自适配器,Spinner是View类的一个子类。

 1 package com.example.uiconrrol;
2
3 import android.app.Activity;
4 import android.os.Bundle;
5 import android.widget.ArrayAdapter;
6 import android.widget.Spinner;
7
8 public class AtyUsingSpinner extends Activity {
9
10 private Spinner spinner;
11 private ArrayAdapter<String> adapter;
12
13 @Override
14 protected void onCreate(Bundle savedInstanceState) {
15 super.onCreate(savedInstanceState);
16 setContentView(R.layout.aty_using_spinner);
17
18 adapter = new ArrayAdapter<String>(this,
19 android.R.layout.simple_spinner_item);
20 adapter.add("1");
21 adapter.add("2");
22 adapter.add("3");
23 adapter.add("4");
24
25 spinner = (Spinner) findViewById(R.id.spinner);
26 spinner.setAdapter(adapter);
27 }
28 }

AtyUsingSpinner

 1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 android:orientation="vertical" >
6
7 <Spinner
8 android:id="@+id/spinner"
9 android:layout_width="match_parent"
10 android:layout_height="wrap_content" />
11
12 </LinearLayout>

aty_using_spinner.xml

6. ProgressBar

  ProgressBar是一个进度条控件,当用户在后台执行一些任务时,在前台展示的信息,用于表示任务正在处理,请用户等待或者给用户展示处理的进度消息等,它在android源代码中是直接继承View类的。

 1 package com.example.uiconrrol;
2
3 import java.util.Timer;
4 import java.util.TimerTask;
5
6 import android.app.Activity;
7 import android.os.Bundle;
8 import android.widget.ProgressBar;
9
10 public class AtyUsingProgressBar extends Activity {
11
12 private ProgressBar pb;
13
14 @Override
15 protected void onCreate(Bundle savedInstanceState) {
16 super.onCreate(savedInstanceState);
17 setContentView(R.layout.aty_using_progressbar);
18
19 pb = (ProgressBar) findViewById(R.id.progressBar);
20 pb.setMax(100);
21
22 }
23
24 @Override
25 protected void onResume() {
26 super.onResume();
27
28 startTimer();
29 }
30
31 @Override
32 protected void onPause() {
33 super.onPause();
34
35 stopTimer();
36 }
37
38 private int progress = 0;
39
40 public void startTimer() {
41 if (timer == null) {
42 timer = new Timer();
43 task = new TimerTask() {
44
45 @Override
46 public void run() {
47
48 progress++;
49 pb.setProgress(progress);
50
51 }
52 };
53 timer.scheduleAtFixedRate(task, 1000, 500);
54 }
55 }
56
57 public void stopTimer() {
58 if (timer != null) {
59 task.cancel();
60 timer.cancel();
61
62 task = null;
63 timer = null;
64 }
65 }
66
67 private Timer timer = null;
68 private TimerTask task = null;
69 }

AtyUsingProgressBar

 1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 android:orientation="vertical" >
6
7 <ProgressBar
8 android:id="@+id/progressBar2"
9 android:layout_width="wrap_content"
10 android:layout_height="wrap_content" />
11
12 <ProgressBar
13 android:id="@+id/progressBar3"
14 style="?android:attr/progressBarStyleLarge"
15 android:layout_width="wrap_content"
16 android:layout_height="wrap_content" />
17
18 <ProgressBar
19 android:id="@+id/progressBar"
20 style="?android:attr/progressBarStyleHorizontal"
21 android:layout_width="fill_parent"
22 android:layout_height="wrap_content" />
23
24 </LinearLayout>

aty_using_progressbar.xml

7. SeekBar

  SeekBar控件其实是相对高级的进度条,是可以拖动的,可以改变进度的一个进度条控件。

 1 package com.example.uiconrrol;
2
3 import android.app.Activity;
4 import android.os.Bundle;
5 import android.widget.SeekBar;
6 import android.widget.TextView;
7
8 public class AtyUsingSeekBar extends Activity {
9
10 private SeekBar seekBar;
11 private TextView txOut;
12
13 @Override
14 protected void onCreate(Bundle savedInstanceState) {
15 super.onCreate(savedInstanceState);
16 setContentView(R.layout.aty_using_seekbar);
17
18 txOut = (TextView) findViewById(R.id.txOut);
19
20 seekBar = (SeekBar) findViewById(R.id.seekBar);
21 seekBar.setMax(100);
22 seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
23
24 @Override
25 public void onStopTrackingTouch(SeekBar seekBar) {
26
27 }
28
29 @Override
30 public void onStartTrackingTouch(SeekBar seekBar) {
31
32 }
33
34 @Override
35 public void onProgressChanged(SeekBar seekBar, int progress,
36 boolean fromUser) {
37 txOut.setText(String.format("当前进度为:%d", progress) + "%");
38 }
39 });
40
41 }
42 }

AtyUsingSeekBar

 1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 android:orientation="vertical" >
6
7 <SeekBar
8 android:id="@+id/seekBar"
9 android:layout_width="match_parent"
10 android:layout_height="wrap_content" />
11
12 <TextView
13 android:id="@+id/txOut"
14 android:layout_width="fill_parent"
15 android:layout_height="wrap_content"
16 android:text="TextView" />
17
18 </LinearLayout>

aty_using_seekbar.xml

8. GridView

  GridView(网格视图)是按照行列的方式来显示内容的,一般用于显示图片等内容,比如实现九宫格图,用GridView是首选,也是最简单的。

 1 package com.example.uiconrrol;
2
3 import android.app.Activity;
4 import android.os.Bundle;
5 import android.widget.ArrayAdapter;
6 import android.widget.GridView;
7
8 public class AtyUsingGridView extends Activity {
9
10 private ArrayAdapter<String> adapter;
11 private GridView gridView;
12
13 @Override
14 protected void onCreate(Bundle savedInstanceState) {
15 super.onCreate(savedInstanceState);
16 setContentView(R.layout.aty_using_gridview);
17
18 adapter = new ArrayAdapter<String>(this,
19 android.R.layout.simple_list_item_1);
20
21 gridView = (GridView) findViewById(R.id.gridView);
22 gridView.setAdapter(adapter);
23
24 for (int i = 0; i < 60; i++) {
25 adapter.add("Nankai" + i);
26 }
27 }
28 }

AtyUsingGridView

 1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 android:orientation="vertical" >
6
7 <GridView
8 android:id="@+id/gridView"
9 android:layout_width="match_parent"
10 android:layout_height="fill_parent"
11 android:numColumns="3" >
12 </GridView>
13
14 </LinearLayout>

aty_using_gridview.xml

9. ProgressDialog

  ProgressDialog,顾名思义,就是一个进度对话框,常用于显示载入进度、下载进度等,合理使用ProgressDialog能增加用户体验,让用户知道现在程序所处的状态。

 1 package com.example.uiconrrol;
2
3 import android.app.Activity;
4 import android.app.ProgressDialog;
5 import android.os.Bundle;
6 import android.view.View;
7
8 public class AtyUsingProgressDialog extends Activity {
9
10 private ProgressDialog progressDialog;
11
12 @Override
13 protected void onCreate(Bundle savedInstanceState) {
14 super.onCreate(savedInstanceState);
15 setContentView(R.layout.aty_using_progressdialog);
16
17 findViewById(R.id.btnShowProgressDialog).setOnClickListener(
18 new View.OnClickListener() {
19
20 @Override
21 public void onClick(View v) {
22 progressDialog = ProgressDialog.show(
23 AtyUsingProgressDialog.this, "加载中", "正在加载,请稍后");
24
25 new Thread() {
26 public void run() {
27 try {
28 Thread.sleep(3000);
29
30 progressDialog.dismiss();
31 } catch (InterruptedException e) {
32 e.printStackTrace();
33 }
34 };
35 }.start();
36 }
37 });
38 }
39 }

AtyUsingProgressDialog

 1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 android:orientation="vertical" >
6
7 <Button
8 android:id="@+id/btnShowProgressDialog"
9 android:layout_width="wrap_content"
10 android:layout_height="wrap_content"
11 android:text="Show Progress Dialog" />
12
13 </LinearLayout>

aty_using_progressdialog.xml

10. Notification

  Notification是Android中常用的一种通知方式,当有未读短信或未接电话的时候,屏幕状态栏就会有提示图标,这时可以下拉状态栏来读取通知。在使用微信的时(微信在后台运行),如果有新消息时便会发出声音提示,状态栏也有相应的微信提示。

 1 package com.example.uiconrrol;
2
3 import android.app.Activity;
4 import android.app.Notification;
5 import android.app.NotificationManager;
6 import android.app.PendingIntent;
7 import android.content.Context;
8 import android.os.Bundle;
9 import android.view.View;
10
11 public class AtyUsingNotification extends Activity {
12
13 private NotificationManager nm;
14
15 @Override
16 protected void onCreate(Bundle savedInstanceState) {
17 super.onCreate(savedInstanceState);
18 setContentView(R.layout.aty_using_notification);
19
20 nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
21 nm.cancel(R.layout.aty_using_notification);
22
23 findViewById(R.id.btnShowNotification).setOnClickListener(new View.OnClickListener() {
24
25 @Override
26 public void onClick(View v) {
27 Notification n = new Notification(R.drawable.ic_launcher, "Ticker Text", System.currentTimeMillis());
28 n.setLatestEventInfo(AtyUsingNotification.this, "Title", "content", PendingIntent.getActivity(AtyUsingNotification.this, 1, getIntent(), 0));
29 nm.notify(R.layout.aty_using_notification, n);
30 }
31 });
32 }
33 }

AtyUsingNotification

 1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 android:orientation="vertical" >
6
7 <Button
8 android:id="@+id/btnShowNotification"
9 android:layout_width="wrap_content"
10 android:layout_height="wrap_content"
11 android:text="Button" />
12
13 </LinearLayout>

aty_using_notification.xml

11. ScrollView

  ScrollView滚动视图是指当拥有很多内容,屏幕显示不完时,需要通过滚动跳来显示的视图。ScrollView只支持垂直滚动。

 1 package com.example.uiconrrol;
2
3 import android.app.Activity;
4 import android.os.Bundle;
5
6 public class AtyUsingSrcollView extends Activity {
7
8 @Override
9 protected void onCreate(Bundle savedInstanceState) {
10 super.onCreate(savedInstanceState);
11 setContentView(R.layout.aty_using_scrollview);
12 }
13 }

AtyUsingSrcollView

  1 <?xml version="1.0" encoding="utf-8"?>
2 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent" >
5
6 <LinearLayout
7 android:layout_width="fill_parent"
8 android:layout_height="wrap_content"
9 android:orientation="vertical" >
10
11 <TextView
12 android:id="@+id/textView1"
13 android:layout_width="wrap_content"
14 android:layout_height="wrap_content"
15 android:text="TextView" />
16
17 <EditText
18 android:id="@+id/editText1"
19 android:layout_width="match_parent"
20 android:layout_height="wrap_content"
21 android:ems="10"
22 android:inputType="textMultiLine" >
23
24 <requestFocus />
25 </EditText>
26
27 <EditText
28 android:id="@+id/editText2"
29 android:layout_width="match_parent"
30 android:layout_height="wrap_content"
31 android:ems="10"
32 android:inputType="textPersonName" />
33
34 <Spinner
35 android:id="@+id/spinner1"
36 android:layout_width="match_parent"
37 android:layout_height="wrap_content" />
38
39 <Button
40 android:id="@+id/button1"
41 style="?android:attr/buttonStyleSmall"
42 android:layout_width="wrap_content"
43 android:layout_height="wrap_content"
44 android:text="Button" />
45
46 <EditText
47 android:id="@+id/editText3"
48 android:layout_width="match_parent"
49 android:layout_height="wrap_content"
50 android:ems="10"
51 android:inputType="textPostalAddress" />
52
53 <ProgressBar
54 android:id="@+id/progressBar1"
55 style="?android:attr/progressBarStyleLarge"
56 android:layout_width="wrap_content"
57 android:layout_height="wrap_content" />
58
59 <Spinner
60 android:id="@+id/spinner2"
61 android:layout_width="match_parent"
62 android:layout_height="wrap_content" />
63
64 <RatingBar
65 android:id="@+id/ratingBar1"
66 android:layout_width="wrap_content"
67 android:layout_height="wrap_content" />
68
69 <RadioGroup
70 android:id="@+id/radioGroup2"
71 android:layout_width="wrap_content"
72 android:layout_height="wrap_content" >
73
74 <RadioButton
75 android:id="@+id/radio0"
76 android:layout_width="wrap_content"
77 android:layout_height="wrap_content"
78 android:checked="true"
79 android:text="RadioButton" />
80
81 <RadioButton
82 android:id="@+id/radio1"
83 android:layout_width="wrap_content"
84 android:layout_height="wrap_content"
85 android:text="RadioButton" />
86
87 <RadioButton
88 android:id="@+id/radio2"
89 android:layout_width="wrap_content"
90 android:layout_height="wrap_content"
91 android:text="RadioButton" />
92 </RadioGroup>
93
94 <RadioGroup
95 android:id="@+id/radioGroup1"
96 android:layout_width="wrap_content"
97 android:layout_height="wrap_content" >
98
99 <RadioButton
100 android:id="@+id/radio3"
101 android:layout_width="wrap_content"
102 android:layout_height="wrap_content"
103 android:checked="true"
104 android:text="RadioButton" />
105
106 <RadioButton
107 android:id="@+id/radio4"
108 android:layout_width="wrap_content"
109 android:layout_height="wrap_content"
110 android:text="RadioButton" />
111
112 <RadioButton
113 android:id="@+id/radio5"
114 android:layout_width="wrap_content"
115 android:layout_height="wrap_content"
116 android:text="RadioButton" />
117 </RadioGroup>
118 </LinearLayout>
119
120 </ScrollView>

aty_using_scrollview.xml

12. RatingBar

  RatingBar是SeekBar和ProgressBar的扩展,用星星来评级,使用的默认大小RatingBar时,用户可以触摸/拖动或使用键来设置评分,它有大小两种样式,其中大的只适合指示,不适合于用户交互。

 1 package com.example.uiconrrol;
2
3 import android.app.Activity;
4 import android.os.Bundle;
5 import android.widget.RatingBar;
6 import android.widget.Toast;
7
8 public class AtyUsingRatingBar extends Activity {
9
10 private RatingBar ratingBar;
11
12 @Override
13 protected void onCreate(Bundle savedInstanceState) {
14 super.onCreate(savedInstanceState);
15 setContentView(R.layout.aty_using_ratingbar);
16
17 ratingBar = (RatingBar) findViewById(R.id.ratingBar);
18 ratingBar
19 .setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
20
21 @Override
22 public void onRatingChanged(RatingBar ratingBar,
23 float rating, boolean fromUser) {
24 Toast.makeText(AtyUsingRatingBar.this,
25 "评价为: " + rating, Toast.LENGTH_SHORT).show();
26 }
27 });
28 }
29 }

AtyUsingRatingBar

 1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="match_parent"
4 android:layout_height="match_parent"
5 android:orientation="vertical" >
6
7 <RatingBar
8 android:id="@+id/ratingBar"
9 android:layout_width="wrap_content"
10 android:layout_height="wrap_content" />
11
12 </LinearLayout>

aty_using_ratingbar.xml

08_UI控件的更多相关文章

  1. JS调用Android、Ios原生控件

    在上一篇博客中已经和大家聊了,关于JS与Android.Ios原生控件之间相互通信的详细代码实现,今天我们一起聊一下JS调用Android.Ios通信的相同点和不同点,以便帮助我们在进行混合式开发时, ...

  2. HTML5 progress和meter控件

    在HTML5中,新增了progress和meter控件.progress控件为进度条控件,可表示任务的进度,如Windows系统中软件的安装.文件的复制等场景的进度.meter控件为计量条控件,表示某 ...

  3. 百度 flash html5自切换 多文件异步上传控件webuploader基本用法

    双核浏览器下在chrome内核中使用uploadify总有302问题,也不知道如何修复,之所以喜欢360浏览器是因为帮客户控制渲染内核: 若页面需默认用极速核,增加标签:<meta name=& ...

  4. JS与APP原生控件交互

    "热更新"."热部署"相信对于混合式开发的童鞋一定不陌生,那么APP怎么避免每次升级都要在APP应用商店发布呢?这里就用到了混合式开发的概念,对于电商网站尤其显 ...

  5. UWP开发必备:常用数据列表控件汇总比较

    今天是想通过实例将UWP开发常用的数据列表做汇总比较,作为以后项目开发参考.UWP开发必备知识点总结请参照[UWP开发必备以及常用知识点总结]. 本次主要讨论以下控件: GridView:用于显示数据 ...

  6. 【踩坑速记】开源日历控件,顺便全面解析开源库打包发布到Bintray/Jcenter全过程(新),让开源更简单~

    一.写在前面 自使用android studio开始,就被它独特的依赖方式:compile 'com.android.support:appcompat-v7:25.0.1'所深深吸引,自从有了它,麻 ...

  7. 对百度WebUploader开源上传控件的二次封装,精简前端代码(两句代码搞定上传)

    前言 首先声明一下,我这个是对WebUploader开源上传控件的二次封装,底层还是WebUploader实现的,只是为了更简洁的使用他而已. 下面先介绍一下WebUploader 简介: WebUp ...

  8. Windows API 设置窗口下控件Enable属性

    参考页面: http://www.yuanjiaocheng.net/webapi/create-crud-api-1-put.html http://www.yuanjiaocheng.net/we ...

  9. VB.NET设置控件和窗体的显示级别

    前言:在用VB.NET开发射频检测系统ADS时,当激活已存在的目标MDI子窗体时,被其他子窗体遮住了,导致目标MDI子窗体不能显示. 这个问题怎么解决呢?网上看到一篇帖子VB.NET设置控件和窗体的显 ...

随机推荐

  1. 【Luogu】P1436 棋盘分割 题解

    嗯,点开题目,哇!是一道闪亮亮的蓝题! 不要被吓到了,其实,这道题就是一个简单的DP啦! 我们设 \(f[x1][y1][x2][y2][c]\) 为以 \((x1,y1)\) 为左上角,以 \((x ...

  2. 我的第三次C语言作业

    我的第三次C语言作业 这个作业属于哪个课程 https://edu.cnblogs.com/campus/zswxy/SE2020-2 这个作业要求在哪里 https://edu.cnblogs.co ...

  3. 11/6笔记 补充(Redis持久化,RDB&&AOF)

    11/6补充笔记 修改redis-6379.conf里面的save10秒2个数据发生改变 (save 10 2) 修改一次数据不发生改变,修改2次数据才发生改变 继续修改数据,发现还是一样的规律 增删 ...

  4. Flink的sink实战之二:kafka

    欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...

  5. FullCalendar v5.3.2版本制作一个航班日历Demo

    今天一个新需求是制作一个航班日历来订舱.然后我就各种找,最后找到FullCalendar,过程非常煎熬,网上例子大部分没用,大部分没有完整版.官网教程又不是很详细.搞了几天才彻底搞好这个航班日历,有需 ...

  6. nginx vhost配置

    server { listen 80; server_name crsdemo.my; index index.html index.htm index.php default.html defaul ...

  7. 1.1 Prism安装

    Prism框架有很多安装包,即便用了很长一段时间,也可能会不知道如何安装框架.细心分析包的依赖关系,发现所有包均依赖与依赖注入扩展插件,以使用Unity为例,Prism.Unity依赖Prism.Wp ...

  8. Unix/Linux常用文件操作

    Unix/Linux常用文件操作 秘籍:man命令是Unix/Linux中最常用的命令,因为命令行命令过多,我相信每个人都会经常忘记某些命令的用法,man命令就可以显示一个命令的所有选项,参数和说明, ...

  9. 企业网络拓扑RSTP功能实例

    组网图形  RSTP简介 以太网交换网络中为了进行链路备份,提高网络可靠性,通常会使用冗余链路.但是使用冗余链路会在交换网络上产生环路,引发广播风暴以及MAC地址表不稳定等故障现象,从而导致用户通信质 ...

  10. MCscan-Python-jcvi 共线性画图最后一章更新

    经过几轮调试和修改,共线性图终于可以上眼了.如下: 图中红色的为目标基因,蓝色的为reference species目标基因周围15个基因,天蓝色为再往外15个基因,黄色为与reference spe ...