我正在开发一个Android应用程序,我想只为大屏幕和超大屏幕启用横向模式。因为我在 oncreate()方法中编写以下代码
int screenSize = getResources().getConfiguration().screenLayout &
Configuration.SCREENLAYOUT_SIZE_MASK;
switch(screenSize) {
case Configuration.SCREENLAYOUT_SIZE_LARGE:
Toast.makeText(this, "Large screen",Toast.LENGTH_LONG).show();
break;
case Configuration.SCREENLAYOUT_SIZE_NORMAL:
Toast.makeText(this, "Normal screen",Toast.LENGTH_LONG).show();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
break;
case Configuration.SCREENLAYOUT_SIZE_SMALL:
Toast.makeText(this, "Small screen",Toast.LENGTH_LONG).show();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
break;
case Configuration.SCREENLAYOUT_SIZE_XLARGE:
Toast.makeText(this, "Small screen",Toast.LENGTH_LONG).show();
break;
default:
Toast.makeText(this, "Screen size is neither large, normal or small" , Toast.LENGTH_LONG).show();
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
在我的oncreate()方法中编写此代码后,每次单击事件的响应变得非常慢。
我将布局文件作为参考
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/blue_bg"
>
<!-- Menu Panel -->
<RelativeLayout
android:id="@+id/menuPanel"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:gravity="right"
android:background="@drawable/gray_bg"
android:orientation="vertical" >
<TextView
android:id="@+id/menu_title_1"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="0dp"
android:paddingLeft="15dp"
android:gravity="center_vertical"
android:background="#353535"
android:textColor="@android:color/white"
android:text="@string/menu_title">
</TextView>
<View
android:id="@+id/menu_item_divider_1"
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_below="@+id/menu_title_1"
android:background="#b5b5b5"/>
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/menu_item_divider_1"
android:dividerHeight="1dp"
android:id="@+id/list"
></ListView>
</RelativeLayout>
<!-- Sliding Panel -->
<LinearLayout
android:id="@+id/slidingPanel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="left"
android:orientation="vertical"
android:background="@android:color/white" >
<RelativeLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/blue_bg" >
<View
android:id="@+id/header_vertical_divider_1"
android:layout_width="2dp"
android:layout_height="fill_parent"
android:layout_alignParentTop="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/menuViewButton"
android:background="@drawable/engraved_bg" />
**<ImageView
android:id="@+id/menuViewButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:clickable="true"
android:contentDescription="@string/description"
android:src="@drawable/icon_menu"
android:visibility="visible"
android:OnClick="slidewindow"/>**</RelativeLayout>
<View
android:id="@+id/dividerHeaderBottom"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#414141" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:layout_marginLeft="30dp"
android:layout_marginRight ="30dp"
android:id="@+id/fragment"
android:background="@drawable/rounded_edittext"
android:layout_marginBottom="30dp"
>
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/blue_bg" />
</RelativeLayout>
</LinearLayout>
</FrameLayout>
menuview 按钮ID点击事件仅在我在该点击事件中编写 Configuration.SCREENLAYOUT_SIZE_SMALL 代码时才有效。您可以解释为什么检查后响应变得非常慢oncreate()方法中的屏幕大小。如果不正确,请告诉我替代方案。