弄android也有一段时间了,之前一直在看基础,后面想想或许做一个实例出来会明白的更多;
然后弄了一个android的闹钟,也在网上找了许多闹钟的实例,在开始的时候看着都不是很明白,再加上那些实例基本没什么注释,后面也发现了一些好的简单的实力,好了.废话不多说,现在来总结一下我的android闹钟吧.
界面:
做一个闹钟,先要弄好布局文件:mian.xml
需要用到的控件有 Button TextView DigitalClock AnalogClock
Button和TextView就不多说了, DigitalClock是用于显示数字的时间的, AnalogClock是用于显示图表的时间,下面是main.xml的代码:
<?xmlversion="1.0"encoding="utf-8"?>
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/black"
>
<AnalogClock
android:id="@+id/analogClock"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<DigitalClock
android:gravity="center"
android:id="@+id/dclock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_x="30px"
android:layout_y="32px"
android:textSize="55sp"/>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/textview2"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:gravity="right"
android:text="起床闹钟设置为:"/>
<TextView
android:id="@+id/textview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="@string/hello"/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:gravity="center"
android:layout_weight