我需要在主佈局活動(排列成3行5列)上對此佈局充氣15次,併爲每個按鈕設置OnTouchListener,wath是最好的方法去做吧??我試圖誇大佈局,但沒有想法設置監聽分離...將OnTouchListener設置爲包含在xml充氣中的多個按鈕
佈局膨脹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>
主要佈局(容器)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>
是在OnTouchListener總是爲每個按鈕的縫隙?或者你想爲每個按鈕明確不同的操作? – 2013-03-19 19:26:37
然而,我不確定你可以有多個按鈕具有相同的ID ... – 2013-03-19 19:34:19
如果我設置每個按鈕的標籤我可以做什麼?例如:button.setTag等等... 我需要一個例子以正確的方式獲得佈局。我可以使用for循環? – kosma822 2013-03-19 19:49:33