0
我試圖創建一個自定義的dopdown項目佈局,使項目之間有更多的空間。 本來我有這個代碼:自定義下拉項目佈局在Android中沒有效果
MyListAdapter adapter = new MyListAdapter (this, tmpData);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
這是Android系統內置的佈局:
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
style="?android:attr/spinnerDropDownItemStyle"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="?android:attr/dropdownListPreferredItemHeight"
android:ellipsize="marquee" />
我修改了代碼,以這樣的:
MyListAdapter adapter = new MyListAdapter (this, tmpData);
adapter.setDropDownViewResource(R.layout.custom_simple_spinner_dropdown_item);
並用此佈局:
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:layout_marginBottom="24dp"
android:layout_marginTop="24dp"
/>
沒有什麼改變。
你能告訴我爲什麼嗎?
您需要使用另一個自定義XML文件來實現此目的。你能顯示那個文件嗎? – Dhaval
你的XML是什麼意思?該佈局僅包含該CheckedTextView。 – Nestor
你不使用「R.layout.custom_simple_spinner_dropdown_item」嗎?似乎你錯過了「R.」。這不是給你錯誤嗎? – Dhaval