最后的效果图为:
1、main.xml
[java]view plain copy print ?<?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns:android="/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@drawable/b" > <Button android:id="@+id/bt_shake" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/shake" android:text="晃动打电话" android:onClick="goShake" /> <Button android:id="@+id/bt_rotate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/rotate" android:text="旋转锁屏" android:onClick="goRotate" /> </LinearLayout>
2、shake.xml
[java]view plain copy print ?<?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns:android="/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@drawable/a"> <Buttonandroid:id="@+id/clear" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="hello_world" /> </LinearLayout>
3、rotate.xml
[java]view plain copy print ?<?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns:android="/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@drawable/c"> <TextView android:id="@+id/tv1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="hello_world"/> </LinearLayout>
-------------------以上UI的编写,接下来是逻辑功能的实现
4、MainActivity
[java]view plain copy print ?packagecom.njupt.zzt_love_hjd; importandroid.os.Bundle; importandroid.app.Activity; importandroid.content.Intent; importandroid.view.Menu; importandroid.view.View;