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 :

Lenteur rotation / affichage du clavier (redimensionnement)


Sujet :

Android

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mai 2014
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : France, Côtes d'Armor (Bretagne)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2014
    Messages : 2
    Points : 1
    Points
    1
    Par défaut Lenteur rotation / affichage du clavier (redimensionnement)
    Bonjour,

    C'est la première fois que j'écris sur ce forum et peut-être la première fois que j'écris sur un forum pour avoir de l'aide ...
    J'ai un soucis qu'il me semble avoir déjà rencontré un jour mais je n'arrive plus à corriger, il me semble que c'est dû à un recalcul total des layouts mais je ne suis pas sûr :
    Quand j'affiche un layout avec plus de 50 layouts (avec un scroll en parent) la rotation de l'écran met environ 5 secondes ainsi que l'affichage du clavier (qui redimensionne donc la fenêtre).
    Les layouts se placent dynamiquement dans liste_top50 (LinearLayout)
    Ces layouts sont "groupe_pistes" qui sont eux aussi complété par des "piste"

    Le tout est généré en Inflater.

    Voici le dessin de tout ça :
    activity_main.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
     
            <RelativeLayout
                android:id="@+id/pnl_top50"
                android:visibility="invisible"
                android:layout_width="match_parent"
                android:layout_height="match_parent" >
     
                <com.easy2soft.musiques.Scolleur
                    android:id="@+id/parent_liste_top50"
                    android:layout_width="match_parent"
                    android:layerType="hardware"
                    android:layout_height="match_parent" >
     
                    <LinearLayout
                        android:id="@+id/liste_top50"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="10dp"
                        android:layout_marginRight="10dp"
                        android:orientation="vertical" >
     
                    </LinearLayout>
                </com.easy2soft.musiques.Scolleur>
     
            </RelativeLayout>
    groupe_piste.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
     
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="10dp"
         >
        <TextView
            android:id="@+id/titre_groupe"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:textColor="#489c23"
            android:textSize="18dp"
            android:background="@drawable/bg_titre_groupe"
            android:text="# (2 pistes)" />
     
        <LinearLayout
            android:id="@+id/liste_groupe"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_marginTop="5dp"
            android:layout_below="@+id/titre_groupe"
            android:orientation="vertical" >
     
        </LinearLayout>
     
    </RelativeLayout>
    piste.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
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
     
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:hapticFeedbackEnabled="true"
        android:clickable="true"
        android:longClickable="true"
        android:soundEffectsEnabled="true"
        android:background="@drawable/bg_item"
        >
     
        <ImageView
            android:id="@+id/piste_pochette"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:layout_margin="4dp"
            android:background="#489c23"
            android:padding="0dp"
            android:scaleType="centerCrop"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:src="@drawable/ic_launcher" />
     
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="64dp"
            android:layout_marginRight="4dp"
            android:layout_alignTop="@+id/piste_pochette"
            android:layout_toRightOf="@+id/piste_pochette"
            android:orientation="horizontal"
             >
     
            <LinearLayout
                android:id="@+id/piste_champs"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginRight="64dp"
                android:orientation="vertical" >
     
                <TextView
                    android:id="@+id/piste_titre"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textStyle="bold"
                    android:textColor="#030303"
                    android:ellipsize="end"
                    android:lines="1"
                    android:textSize="16dp"
                    android:text="01 California Gurls" />
     
                <TextView
                    android:id="@+id/piste_auteur"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="#363636"
                    android:textSize="14dp"
                    android:layout_marginTop="-1dp"
                    android:ellipsize="end"
                    android:lines="1"
                    android:text="Katy Perry" />
                <TextView
                    android:id="@+id/piste_infos"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="#363636"
                    android:textSize="14dp"
                    android:layout_marginTop="-1dp"
                    android:ellipsize="end"
                    android:lines="1"
                    android:text="4.54Mo / 192K" />
     
            </LinearLayout>
     
            <LinearLayout
                android:id="@+id/piste_actions"
                android:layout_width="64dp"
                android:layout_height="match_parent"
                android:layout_gravity="right"
                android:layout_marginLeft="-64dp"
                android:visibility="invisible"
                android:orientation="horizontal" >
     
                <ImageView
                    android:id="@+id/piste_btn_download"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_marginLeft="2dp"
                    android:background="@drawable/bg_icon"
                    android:padding="5dp"
                    android:src="@android:drawable/stat_sys_download_done" />
                <ImageView
                    android:id="@+id/piste_btn_play"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_marginLeft="2dp"
                    android:background="@drawable/bg_icon"
                    android:padding="3dp"
                    android:src="@android:drawable/ic_media_play" />
     
            </LinearLayout>
     
        </LinearLayout>
     
        <TextView
            android:id="@+id/piste_url_pochette"
            android:visibility="invisible"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="" />
     
    </RelativeLayout>
    Morceau du code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    										final GroupeMusic grp=new GroupeMusic(obj.getString("titre"));
    										grp.setPistes(obj.getJSONArray("pistes"));
    										runOnUiThread(new Runnable() {
     
    											@Override
    											public void run() {
    												// TODO Auto-generated method stub
    												liste.addView(grp.getLayout());												
    											}
    										});
    Class GroupeMusic :
    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
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
     
    	class GroupeMusic
    	{
    		private RelativeLayout groupe=null;
    		public GroupeMusic()
    		{
    			init();
    		}
    		public GroupeMusic(String libelle)
    		{
    			init();
    			setLibelle(libelle);
    		}
    		@SuppressLint("NewApi")
    		private void init()
    		{
    			groupe=(RelativeLayout)getLayoutInflater().inflate(R.layout.groupe_piste, null);
    			/*
    			RelativeLayout.LayoutParams lp=new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
    			lp.setMargins(10, 10, 10, 10);
    			groupe.setLayoutParams(lp);
    			*/
    		}
    		public void clearPistes()
    		{
    			((LinearLayout)groupe.findViewById(R.id.liste_groupe)).removeAllViews();
    		}
    		public void addPiste(final String titre, final String auteur,final  String infos, final String id,final String pochette)
    		{
    			new Thread(new Runnable() {
     
    				@Override
    				public void run() {
    					// TODO Auto-generated method stub
    					final RelativeLayout tmp=(RelativeLayout)getLayoutInflater().inflate(R.layout.piste, null);
    					tmp.setOnClickListener(new View.OnClickListener() {
     
    						@Override
    						public void onClick(View v) {
    							// TODO Auto-generated method stub
    							lireAudio(v.getId()-1000,((TextView)v.findViewById(R.id.piste_auteur)).getText().toString(),((TextView)v.findViewById(R.id.piste_titre)).getText().toString(),((TextView)v.findViewById(R.id.piste_url_pochette)).getText().toString());
    						}
    					});
    					tmp.setId(Integer.parseInt(id)+1000);
    					((TextView)tmp.findViewById(R.id.piste_url_pochette)).setText(Constantes.serveur+"/pochette-"+pochette+".png");
    					((TextView)tmp.findViewById(R.id.piste_titre)).setText(titre);
    					((TextView)tmp.findViewById(R.id.piste_auteur)).setText(auteur);
    					((TextView)tmp.findViewById(R.id.piste_infos)).setText(infos);
    					pochettes.add(Constantes.serveur+"/pochette-"+pochette+".png");
    					Log.i("addPiste", "add : "+pochette+" ("+pochettes.size()+")");
    					runOnUiThread(new Runnable() {
     
    						@Override
    						public void run() {
    							// TODO Auto-generated method stub
    							((LinearLayout)groupe.findViewById(R.id.liste_groupe)).addView(tmp);
     
    						}
    					});
    					try {
    						Thread.sleep(100);
    					} catch (InterruptedException e) {
    						// TODO Auto-generated catch block
    						e.printStackTrace();
    					}
    					//new Images(((ImageView)tmp.findViewById(R.id.piste_pochette))).execute(Constantes.serveur+"/pochette-"+pochette+".png");
    				}
    			}).start();
    		}
    		public void setPistes(final JSONArray pistes)
    		{
    			clearPistes();
    			new Thread(new Runnable() {
     
    				@Override
    				public void run() {
    					// TODO Auto-generated method stub
    					for(int i=0;i<pistes.length();i++)
    					{
    						JSONObject piste = null;
    						try {
    							piste = pistes.getJSONObject(i);
    						} catch (JSONException e) {
    							// TODO Auto-generated catch block
    							e.printStackTrace();
    						}
    						try {
    							addPiste(piste.getString("titre"),piste.getString("auteur"),piste.getString("infos"),piste.getString("id"),piste.getString("url_pochette"));
    						} catch (JSONException e) {
    							// TODO Auto-generated catch block
    							e.printStackTrace();
    						}
    					}					
    				}
    			}).start();
     
    		}
    		public void setLibelle(String libelle)
    		{
    			((TextView)groupe.findViewById(R.id.titre_groupe)).setText(libelle);
    		}
    		public RelativeLayout getLayout()
    		{
    			return groupe;
    		}
    	}
    Sinon il y-a un autre problème, c'est le temps de création de ces layouts mais ça je pense savoir que c'est ma méthode qui est un peu barbare mais je pense pouvoir m'en sortir...

    Merci d'avance pour votre aide.

    [SDK Android 4.4, appareil utilisé pour les tests : Samsung Galaxy Note 3]

  2. #2
    Expert éminent

    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Février 2007
    Messages
    4 253
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2007
    Messages : 4 253
    Points : 7 618
    Points
    7 618
    Billets dans le blog
    3
    Par défaut
    En fait ce que tu veux c'est un ListView.... surtout pas un ScrollView avec 50 layout dessous....
    N'oubliez pas de cliquer sur mais aussi sur si un commentaire vous a été utile !
    Et surtout

  3. #3
    Nouveau Candidat au Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mai 2014
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : France, Côtes d'Armor (Bretagne)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2014
    Messages : 2
    Points : 1
    Points
    1
    Par défaut
    Merci pour votre réponse, effectivement j'avais pensé à remplacer en ListView avec un Adapter mais est-ce que cela va corriger le problème de lenteur de rotation/redimensionnement ou juste mon petit problème de lenteur de création de layout ?

  4. #4
    Expert éminent

    Homme Profil pro
    Ingénieur systèmes et réseaux
    Inscrit en
    Février 2007
    Messages
    4 253
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Ingénieur systèmes et réseaux
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2007
    Messages : 4 253
    Points : 7 618
    Points
    7 618
    Billets dans le blog
    3
    Par défaut
    Les deux mon capitaine

    La ListView sert justement à n'afficher (et conserver en mémoire pour les calculs de dimension et autres) que les layouts visibles (les "items").
    => Pas de création inutile de View non visible (plus rapide)
    => Réutilisation de view existantes précédentes (encore plus rapide)
    => Seulement quelques layout à redimensionner si l'IME doit s'afficher.
    N'oubliez pas de cliquer sur mais aussi sur si un commentaire vous a été utile !
    Et surtout

Discussions similaires

  1. Réponses: 3
    Dernier message: 24/10/2011, 15h23
  2. [WinForms]Lenteur d'affichage formulaire avec image de fond
    Par olixelle dans le forum Général Dotnet
    Réponses: 2
    Dernier message: 06/09/2006, 14h06
  3. lenteur d'affichage des données
    Par Mak2S dans le forum Delphi
    Réponses: 1
    Dernier message: 11/07/2006, 14h16
  4. Problème d'affichage lors du redimensionnement
    Par sidi.elmoctar dans le forum AWT/Swing
    Réponses: 2
    Dernier message: 12/04/2006, 08h44
  5. lenteur d'affichage de requete dans un DBGrid
    Par nico27 dans le forum InterBase
    Réponses: 9
    Dernier message: 23/06/2003, 13h54

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