IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Android Discussion :

Framelayout et fragment


Sujet :

Android

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    315
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2009
    Messages : 315
    Par défaut Framelayout et fragment
    Bonjour,

    J'ai un souci avec un positionnement ds un FrameLayout

    Dans ce FrameLayout, j'affiche un fragment et je voudrais afficher dynamiquement un TextView

    en dessous du Fragment

    Malheureusement , ils se superposent

    Une idée , Merci

    Voici le code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
     
    public void methode_f3(int m3) {
    		Integer i3 = m3;
     
    		FragmentTransaction aft32 = afm.beginTransaction();
    		mFragment2 = (Fragment2) afm.findFragmentByTag("f2");
    	     if (mFragment2 == null) {
    	           mFragment2 = new Fragment2();
    	           aft32.add(R.id.Container_fragment2,mFragment2,"f2");
    	     }
    	     else {
    		 aft32.replace(R.id.Container_fragment2,mFragment2);
    	     }
    	     aft32.addToBackStack(null);
             aft32.commit();
     
    		 FrameLayout fr = (FrameLayout) findViewById(R.id.Container_fragment2);
    	        TextView textDynamic = new TextView(this);
    	        LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
    	        textDynamic.setLayoutParams(lp);
    	        textDynamic.setText("Valeur de i3 : "+ i3.toString());
    	        textDynamic.setTextColor(Color.BLUE);
    	        textDynamic.setTextSize(20);
    	        textDynamic.setPadding(10, 10, 10, 10);
     
    	        fr.addView(textDynamic);
    	}

  2. #2
    Membre éprouvé
    Profil pro
    Inscrit en
    Décembre 2009
    Messages
    141
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2009
    Messages : 141
    Par défaut
    Le Placeholder de ton fragment est peut être un RelativeLayout ?

    Tu ne précises pas, mais ton TextView est ajouté par rapport à ce fragment (le lookup d'id) ?

    Bref, si c'est juste, ça doit venir de ça.

  3. #3
    Membre éclairé
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    315
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2009
    Messages : 315
    Par défaut
    Merci pour la réponse voici

    le .xml de mon fragment(fragment2) et

    le .xml qui contient le FrameLayout(Container_fragment2) ds lequel j'affiche le Fragment


    fragment2.xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
     
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/autreactivity_fragment2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:layout_weight="1">
     
         <TextView
             	android:id="@+id/textefrag_f2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="je suis le fragment f2" />
         <Button 
         		android:id="@+id/bouton_20"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/textefrag_f2"
                android:layout_gravity="center"
                android:text="Bouton_20"/>
     
    </LinearLayout>
    activity_autre.xml
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
     
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/autreactivity_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
     
        <FrameLayout
            android:id="@+id/Container_bouton2"
            android:layout_width="match_parent"
            android:layout_height="150dp"
            android:background="@color/darkorange">
    	    <Button 
    	        android:id="@+id/boutonAAF2"
    	        android:layout_width="wrap_content"
    	        android:layout_height="wrap_content"
    	        android:text="AA_F2"/>
    	 </FrameLayout>
    	 <FrameLayout android:id="@+id/Container_bouton3"
            android:layout_width="match_parent"
            android:layout_height="150dp"
            android:layout_below="@id/Container_bouton2"
            android:background="@color/darkblue">
    	    <Button 
    	        android:id="@+id/boutonAAF3"
    	        android:layout_width="wrap_content"
    	        android:layout_height="wrap_content"
    	        android:text="AA_F3"/>
    	 </FrameLayout>
    	 <FrameLayout 	    
    	    android:id="@+id/Container_fragment2"
            android:layout_width="match_parent"
            android:layout_height="150dp"
            android:layout_below="@id/Container_bouton3"
            android:background="@color/orange">
    	 </FrameLayout>   
    	  <FrameLayout 	    
    	    android:id="@+id/Container_fragment3"
            android:layout_width="match_parent"
            android:layout_height="150dp"
            android:layout_below="@id/Container_fragment2"
            android:background="@color/blue">
    	 </FrameLayout>   
     
    </RelativeLayout>

  4. #4
    Membre éprouvé
    Profil pro
    Inscrit en
    Décembre 2009
    Messages
    141
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2009
    Messages : 141
    Par défaut
    peut être faire un invalidate sur la view hierarchy (en gros il faudrait que le onMeasure soit appelé) comme tu rajoutes
    un élément à la volé au layout ?

    pour l'activité j’essaierai de mettre un match_parent ou wrap_content sur le height plutôt que de coder un 150dp en dur.
    mais normalement ça devrait pas influer ton problème.

  5. #5
    Membre éclairé
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    315
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2009
    Messages : 315
    Par défaut
    J'ai bien une idée: au lieu d'ajouter un TextView au FrameLayout

    On pourrait ajouter unTextView Dynamiquement au Fragment et puis afficher le FrameLayout qui contient le Fragment

    Voici le code mais il n'affiche pas le TexTView

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
     
    public void methode_f3(int m3) {
    		Integer i3 = m3;
     
    		TextView textDynamic = new TextView(this);
    	        LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
    	        textDynamic.setLayoutParams(lp);
    	        textDynamic.setText("Valeur de i3  : "+ i3.toString());
    	        //textDynamic.setBackgroundColor(Color.GREEN);
    	        textDynamic.setTextColor(Color.BLUE);
    	        //textDynamic.setTextScaleX(2);
    	        textDynamic.setTextSize(20);
    	        //textDynamic.isClickable();
    	        textDynamic.setGravity(Gravity.BOTTOM);
    	        textDynamic.setPadding(10, 10, 10, 10);
     
    		FragmentTransaction aft32 = afm.beginTransaction();
    		mFragment2 = (Fragment2) afm.findFragmentByTag("f2");
    	     if (mFragment2 == null) {
    	           mFragment2 = new Fragment2();
    	           LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    	           View v = (View) vi.inflate(R.layout.fragment2, null);
    	           LinearLayout ll = (LinearLayout) v.findViewById(R.id.autreactivity_fragment2);
    	           ll.addView(textDynamic);
    	           aft32.add(R.id.Container_fragment2,mFragment2,"f2");
    	     }
    	     else {
    	    	 LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    	         View v = (View) vi.inflate(R.layout.fragment2, null);
    	         LinearLayout ll = (LinearLayout) v.findViewById(R.id.autreactivity_fragment2);
    	         ll.addView(textDynamic);
    	         aft32.replace(R.id.Container_fragment2,mFragment2);
    	     }
    	     aft32.addToBackStack(null);
             aft32.commit();
    }
    Si une idée lumineuse pouvait surgir ...

  6. #6
    Membre éclairé
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    315
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2009
    Messages : 315
    Par défaut Autre solution
    Autre solution : OK

    Mettre Le TextView ds le Fragment mais le cacher

    Ds Activity , le rendre Visible par Bundle Arguments

    Voici le code

    Fragment
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
     
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/autreactivity_fragment2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">
     
         <TextView
             	android:id="@+id/textefrag_f2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="je suis le fragment f2" />
         <Button 
         		android:id="@+id/bouton_20"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/textefrag_f2"
                android:layout_gravity="center"
                android:text="Bouton_20"/>
         <TextView
             	android:id="@+id/textefrag_f21"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:visibility="invisible"
                android:text="" />
     
    </LinearLayout>
    Pour Activity

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
     
    public void methode_f3(int m3) {
    		Log.w("Impl_3","implementation_3");
    		Integer i3 = m3;
     
    FragmentTransaction aft32 = afm.beginTransaction();
    		mFragment2 = (Fragment2) afm.findFragmentByTag("f2");
    	     if (mFragment2 == null) {
    	           mFragment2 = new Fragment2();
    String suppl = "Valeur de i3 : "+ i3.toString();
    	           Bundle args = new Bundle();
    	           args.putString("passage", suppl);
    	           mFragment2.setArguments(args);
     
    	           aft32.add(R.id.Container_fragment2,mFragment2,"f2");
    }
    	     else {
                     aft32.remove(mFragment2);   // à utiliser suivant les cas
    	    	 mFragment2 = new Fragment2();  // à utiliser suivant les cas
    	    	 String suppl = "Valeur de i3 : "+ i3.toString();
    	         Bundle args = new Bundle();
    	         args.putString("passage", suppl);
    	         mFragment2.setArguments(args);
    	         aft32.replace(R.id.Container_fragment2,mFragment2);
    	     }
    	     aft32.addToBackStack(null);
             aft32.commit();
    }
    Pour Fragment2
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    @Override
    	public View onCreateView(LayoutInflater inflater, ViewGroup container,
    			Bundle savedInstanceState) {
    		vi2 = inflater.inflate(R.layout.fragment2, container, false);
    		Bundle b = getArguments();
    		if(b==null){}
    		else {
    			String s = b.getString("passage");
    			TextView tv = (TextView)vi2.findViewById(R.id.textefrag_f21);
    			tv.setText(s);
                tv.setVisibility(View.VISIBLE);
    		}

    Si çà peut aider , tant mieux

Discussions similaires

  1. RAW + fragmentation
    Par MonsieurAk dans le forum Windows
    Réponses: 2
    Dernier message: 07/04/2005, 19h45
  2. Réponses: 17
    Dernier message: 18/03/2005, 15h56
  3. Fragment & vertex program
    Par charly dans le forum OpenGL
    Réponses: 5
    Dernier message: 19/03/2004, 19h47
  4. fragment program sur geForce4 Ti4200
    Par sebh dans le forum OpenGL
    Réponses: 6
    Dernier message: 03/12/2003, 22h31
  5. Fragmentation du DD
    Par guillaume_pfr dans le forum Administration système
    Réponses: 5
    Dernier message: 05/06/2003, 17h19

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo