我有一个活动,我想根据方向动态添加我的片段,所以我做了以下事情: Calendrier.java
package com.thinline.dm21.calendrier;
public class Calendrier extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.calendrier_main);
//ajouter les fragments Planifications et Calendrier mensuel
ajouterFragments();
}
public void ajouterFragments(){
FragmentTransaction ft = getFragmentManager().beginTransaction();
if(getResources().getConfiguration().orientation == 1){
}
else if(getResources().getConfiguration().orientation == 2){
ft.add(R.id.calendrier_planifictions, new Planifications());
ft.add(R.id.calendrier_calendrierhebdomadaire, new CalendrierHebdomadaire());
}
ft.commit();
}
}
这是我的布局/calendrier_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/calendrier_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
<LinearLayout
android:id="@+id/calendrier_planifictions"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
</LinearLayout>
<RelativeLayout
android:id="@+id/calendrier_calendrierhebdomadaire"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2" >
</RelativeLayout>
</LinearLayout>
和我的布局端口/calendrier.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/calendrier_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
<LinearLayout
android:id="@+id/calendrier_planifictions"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
</LinearLayout>
<RelativeLayout
android:id="@+id/calendrier_calendrierhebdomadaire"
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="2" >
</RelativeLayout>
</LinearLayout>
我的问题是:
- 当我以纵向模式启动我的应用程序时,我得到一个黑屏,当我旋转它时,我得到我的另外两个片段,这很好,但是当我再次旋转它(纵向)时,我仍然有我的片段而不是我的黑屏, 通常它应该显示一个黑屏,因为 onCreate 和 onDestroy 都被执行了