900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > 基于Android重力传感器的编程——摇一摇打电话+旋转锁屏功能的实现

基于Android重力传感器的编程——摇一摇打电话+旋转锁屏功能的实现

时间:2024-05-29 01:48:03

相关推荐

基于Android重力传感器的编程——摇一摇打电话+旋转锁屏功能的实现

最后的效果图为:

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;

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。