Question

Je veux modifier la mise en page de fragment lorsque la configuration changeant en utilisant du fragment ..mais fragment se chevauche dans la mise en page d'activité alors aidez-moi à cela pour cela de résoudre ce ... et ce fichier de classe .........

public class Self_funded_1 extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    Self_fragment ls_fragment = new Self_fragment();
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.self_funded_category);
    Configuration config = getResources().getConfiguration();

    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager
            .beginTransaction();

    if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        /**
         * Landscape mode of the device
         */

        Log.i("LM", "LM");
         ls_fragment = new Self_fragment();
        fragmentTransaction.replace(android.R.id.content, ls_fragment);

    } else {
        /**
         * Portrait mode of the device
         */
        Log.i("LM", "PM");
        PM_self_funded pm_fragment = new PM_self_funded();

        fragmentTransaction.replace(android.R.id.content, pm_fragment);
        fragmentTransaction.remove(ls_fragment);
        fragmentTransaction.hide(ls_fragment);
    }
    fragmentTransaction.commit();
}

Ceci est un fichier XML pour l'activité ..

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >

<fragment
    android:id="@+id/lm_fragment"
    android:name="info.com.forms.Self_fragment"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1" />

<fragment
    android:id="@+id/pm_fragment"
    android:name="info.com.forms.PM_self_funded"
    android:layout_width="0dp"
    android:layout_height="match_parent"
    android:layout_weight="1" />

Ceci est Shot Shot ........

Entrez la description de l'image ici

Était-ce utile?

La solution

Vous déclarez les fragments dans le XML et le programmemactique dans l'activité également.Vous devez simplement choisir une option.

Par exemple, créez deux fichiers de mise en page différents un pour le portrait et un pour le paysage et déclarez les fragments là-bas que vous n'avez pas besoin de faire quelque chose de spécial dans l'activité.

layout/my-layout
layout-land/my-layout

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.my_layout);
}

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top