关于手机启动的方向,和屏幕的单,双击事件
16lz
2021-01-23
方法1:在androidmanyfest.xml的activity中加入属性 android:screenOrientation="landscape"
方法2:在oncreate中加入如下代码 if(getRequestedOrientation()!=ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE){ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);}
这个例子可是很有用的,
点击事件是我们开发中必不可少的一个监听,大
家可要用好它哦
方法2:在oncreate中加入如下代码 if(getRequestedOrientation()!=ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE){ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);}
public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main); //启动横屏if(getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE){setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);}//点击屏幕事件 在开发中很有用的方法哟new GestureDetector(new SimpleOnGestureListener(){@Overridepublic boolean onDoubleTap(MotionEvent e) {// TODO Auto-generated method stubreturn super.onDoubleTap(e);}@Overridepublic boolean onSingleTapConfirmed(MotionEvent e) {// TODO Auto-generated method stubreturn super.onSingleTapConfirmed(e);}@Overridepublic void onLongPress(MotionEvent e) {// TODO Auto-generated method stubsuper.onLongPress(e);}});}}
不要小看这个方法哟
大家可不要小看了这么个例子哦,这个例子可是很有用的,
点击事件是我们开发中必不可少的一个监听,大
家可要用好它哦
更多相关文章
- android 简单例子
- android textview 自动链接网址 修改默认点击事件
- Android处理Bitmap的一些方法
- Android setMovementMethod() 方法
- android 触发AppWidget上控件事件来更新AppWidget
- Android切换主线程更新UI方法总结