[英]Listener for Orientation: Portrait and Landscape?
我有一個計算子網表的應用程序。
但是,如果更改方向,則TextViews將為空。
我為此尋找一個聽眾。 歡迎選擇:D在偵聽器中,我將重新計算表。
在您的活動中使用以下代碼:
@Override
public void onConfigurationChanged(Configuration myConfig) {
super.onConfigurationChanged(myConfig);
int orient = getResources().getConfiguration().orientation;
switch(orient) {
case Configuration.ORIENTATION_LANDSCAPE:
// handle landscape here
break;
case Configuration.ORIENTATION_PORTRAIT:
// handle portrait here
break;
default:
}
}
在清單>活動標簽中添加:
<activity
android:name="com.activity.name"
android:configChanges="orientation|screenSize"
這將防止您在旋轉或更改方向時重新創建活動,因此不會出現空白的TextView(將保留以前的值)
使用OrientationEventListener:
orientationListener = new OrientationEventListener(context, SensorManager.SENSOR_DELAY_UI) {
public void onOrientationChanged(int orientation)
{
//do something
}
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.