J'ai besoin de gonfler cette mise en page 15 fois sur une activité de mise en page principale (disposée en 3 lignes par 5 colonnes), et définir OnTouchListener pour chaque bouton padButton
, wath est la meilleure façon pour le faire?? J'essaie de gonfler la mise en page mais pas idée de mettre en écoute séparés ...Définir OnTouchListener sur un bouton xml gonflé
la mise en page pour gonfler drumpad.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/padLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/pad"
android:orientation="vertical"
android:padding="3dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|clip_horizontal|top"
android:orientation="horizontal" >
<Button
android:id="@+id/padButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/titles2" />
<Button
android:id="@+id/padSelect"
style="?android:attr/buttonStyleSmall"
android:layout_width="15dp"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="21dp" >
<Button
android:id="@+id/padName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="#0f0f0f"
android:padding="2dp"
android:text="@string/pad"
android:textColor="#dfdfdf"
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>
la principale mise en page (conteneur) activity_drum.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/DrumLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#999"
android:gravity="center"
android:orientation="vertical"
tools:context=".Drum" >
</LinearLayout>
Est-ce le OnTouchListener toujours la couture pour chaque bouton? Ou voulez-vous expliciter une action différente pour chaque bouton? –
Cependant, je ne suis pas sûr que vous pouvez avoir plusieurs boutons avec le même id ... –
si je mets le tag pour chaque bouton puis-je faire? exemple: button.setTag etc etc ... J'ai besoin d'un exemple pour obtenir la mise en page de la bonne façon. Je peux utiliser une boucle for? – kosma822