[关闭]
@king 2015-04-08T03:32:29.000000Z 字数 1453 阅读 2184

《疯狂Android讲义》笔记

Android


定义一个线程周期性地执行任务

  1. new Timer().schedule(new TimerTask() {
  2. @Override
  3. public void run() {
  4. ...
  5. }
  6. }, 0, 200);

界面编程

TextView 及其子类

TextView 直接继承了 View, 还是EditText、Button的父类。

EditText允许用户编辑文本框中的内容
CheckedTextView 在文本右侧有个可勾选的方框

圆角边框、渐变背景的TextView:
布局文件:

  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:layout_width="match_parent"
  3. android:layout_height="match_parent"
  4. android:orientation="vertical">
  5. <TextView
  6. android:layout_width="match_parent"
  7. android:layout_height="wrap_content"
  8. android:text="带边框的文本"
  9. android:textSize="24pt"
  10. android:background="@drawable/bg_border"
  11. />
  12. <TextView
  13. android:layout_width="match_parent"
  14. android:layout_height="wrap_content"
  15. android:text="圆角边框、渐变背景的文本"
  16. android:textSize="24pt"
  17. android:background="@drawable/bg_border2"
  18. />
  19. </LinearLayout>

两个drawable文件

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android" >
  3. <!-- 透明背景 -->
  4. <solid android:color="#0000"/>
  5. <!-- 红色边框 -->
  6. <stroke android:width="4px" android:color="#f00"/>
  7. </shape>
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <shape xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:shape="rectangle">
  4. <!-- 指定圆角矩形的4个圆角的半径 -->
  5. <corners
  6. android:topLeftRadius="20px"
  7. android:topRightRadius="5px"
  8. android:bottomRightRadius="20px"
  9. android:bottomLeftRadius="5px"
  10. />
  11. <!-- 指定边框线条的宽度和颜色 -->
  12. <stroke
  13. android:width="4px"
  14. android:color="#f0f"
  15. />
  16. <!-- 指定渐变背景色 -->
  17. <gradient
  18. android:startColor="#f00"
  19. android:centerColor="#0f0"
  20. android:endColor="#00f"
  21. android:type="sweep"
  22. />
  23. </shape>
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注