FrameLayout dans un listview et problème de visibilité
bonjour,
dans mon application Android j'ai rencontré un petit problème :
j'utilise un FrameLayout comme item dans une ListView pour caché un petit menu ( un LinearLayout avec 3 bouton) et l'afficher au clic sur l'item dans la meme positon.
alors le problème est la , quand je modifier la Visibilité du menu ça marche, mais il s'affiche dans la 1er position de la liste même si je clique sur la dernière ou le dernier item !!!
quand on clic sur chaque item je fais ça :
Code:
1 2 3 4
|
LinearLayout layout =(LinearLayout) findViewById(R.id.menu);
layout.setVisibility(View.VISIBLE); |
ici je récupère le menu directement, je pense que c'est la le problème !
voici le fichier item
Code:
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
| <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="10px"
/>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingLeft="10px"
android:layout_weight="1"
>
<TextView android:id="@+id/titre"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="16px"
android:textStyle="bold"
/>
<TextView android:id="@+id/description"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:orientation="horizontal"
android:visibility="invisible" >
<Button
android:id="@+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
<Button
android:id="@+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
</FrameLayout> |
et la j'ajoute mes items a la listview
Code:
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
| map = new HashMap<String, String>();
map.put("titre", "Excel");
map.put("description", "Tableur");
map.put("img", String.valueOf(R.drawable.ic_launcher));
listItem.add(map);
map = new HashMap<String, String>();
map.put("titre", "Power Point");
map.put("description", "Logiciel de présentation");
map.put("img", String.valueOf(R.drawable.ic_launcher));
listItem.add(map);
map = new HashMap<String, String>();
map.put("titre", "Outlook");
map.put("description", "Client de courrier électronique");
map.put("img", String.valueOf(R.drawable.ic_launcher));
listItem.add(map);
SimpleAdapter mSchedule = new SimpleAdapter (this.getBaseContext(), listItem, R.layout.item,
new String[] {"img", "titre", "description"}, new int[] {R.id.img, R.id.titre, R.id.description});
//On attribut à notre listView l'adapter que l'on vient de créer
maListViewPerso.setAdapter(mSchedule);
//Enfin on met un écouteur d'évènement sur notre listView
maListViewPerso.setOnItemClickListener(new OnItemClickListener() {
@Override
@SuppressWarnings("unchecked")
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
LinearLayout layout =(LinearLayout) findViewById(R.id.menu);
layout.setVisibility(View.VISIBLE);
}
});
} |
TranslateAnimation pour ListView après clic (onItemClick)
bonjour,
j'ai enfin trouvé une solution, et c'été pourtant simple mais .... :arf:
donc au début dans mon fichier item j'ai créer 2 Layout dans le Layout principale un qui contient le menu RelativeLayout aligné à droite et invisible Visibility : gone , le deuxième pour le reste voila le code xml :
Code:
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
| <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<LinearLayout
android:id="@+id/item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:orientation="horizontal" >
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="10px" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="10px" >
<TextView
android:id="@+id/titre"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="16px"
android:textStyle="bold" />
<TextView
android:id="@+id/description"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:id="@+id/menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerHorizontal="true"
android:gravity="center_vertical"
android:visibility="gone" >
<ImageButton
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/abc_ic_search" />
<ImageButton
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/imageView1"
android:src="@drawable/abc_ic_cab_done_holo_light" />
<ImageButton
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/imageView2"
android:src="@drawable/abc_ic_clear_normal" />
</RelativeLayout>
</RelativeLayout> |
enfin l'astuce est de faire deux animation Translate avec la même direction et même effet , une pour le menu et l'autre pour le reste ( item) , voici le code java :
Code:
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
| public void onItemClick(AdapterView<?> a, View v, int position,
long id) {
rela =(RelativeLayout) v.findViewById(R.id.menu);
LinearLayout item1= (LinearLayout) v.findViewById(R.id.item);
TranslateAnimation animation = null;
animation = new TranslateAnimation(v.getWidth(), 0.0f, 0.0f,0.0f);
animation.setDuration(1000);
// On ajoute un effet d'accélération
animation.setInterpolator(new AccelerateInterpolator());
// garder les changement
animation.setFillAfter(true);
TranslateAnimation animation1 = null;
animation1 = new TranslateAnimation(0.0f,-v.getWidth()/2, 0.0f,0.0f);
animation1.setDuration(1000);
// On ajoute un effet d'accélération
animation1.setInterpolator(new AccelerateInterpolator());
// garder les changement
animation1.setFillAfter(true);
//animation.setFillEnabled(true);
// Enfin, on lance l'animation
rela.setVisibility(View.VISIBLE);
rela.startAnimation(animation);
item1.startAnimation(animation1);
}
}); |
et voila :) , si vous avez des amélioration n’hésitez pas de les proposé
merci tous le monde :)