我試着像這樣的代碼如何在xml文件中顯示文本旁邊的圖標?
<ImageView android:id="@+id/ivIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_btn_speak_now" />
<TextView
style="@style/behindMenuItemLabel"
android:text="Item0" />
但它輸出這樣的。這不是在同一條線上:(
我的整個XML代碼就是這個樣子。 (icon) item
將是一個集,這將被用戶點擊到的活動而移動。
所以我需要分組在一起。
<LinearLayout style="@style/behindMenuScrollContent"
android:paddingTop="25dp" >
<TextView
style="@style/behindMenuItemTitle"
android:text="Subject" />
<TextView
style="@style/behindMenuItemLabel"
android:text="Item0" />
<TextView
style="@style/behindMenuItemLabel"
android:text="Item1" />
<TextView
style="@style/behindMenuItemLabel"
android:text="Item2" />
<TextView
style="@style/behindMenuItemLabel"
android:text="Item3" />
<TextView
style="@style/behindMenuItemLabel"
android:text="Item4" />
<TextView
style="@style/behindMenuItemLabel"
android:text="Item5" />
<TextView
style="@style/behindMenuItemTitle"
android:text="Subject2" />
<TextView
style="@style/behindMenuItemLabel"
android:text="Item6" />
<TextView
style="@style/behindMenuItemLabel"
android:text="Item7" />
<TextView
style="@style/behindMenuItemLabel"
android:text="Item8" />
<TextView
style="@style/behindMenuItemLabel"
android:text="Item9" />
<TextView
style="@style/behindMenuItemLabel"
android:text="Item10" />
<Button
android:id="@+id/behind_btn"
style="@style/behindMenuItemLabel"
android:text="BUTTON" />
</LinearLayout>
更新:我不需要圖標和文本之間的餘量,但只需要左邊的餘量!
style.xml
<style name="behindMenuItemLabel">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginLeft">20dp</item>
<item name="android:layout_marginBottom">4dp</item>
<item name="android:textSize">30sp</item>
<item name="android:textColor">#d2d2d2</item>
</style>
謝謝。你看起來是我期待的那個。你如何用Style.xml來做這件事? – MKK
有什麼風格(開銷)它更快,更可靠的方式來做到這一點。如果這爲你工作,然後接受這個答案 –
我會的!還有一件事我需要你的是如何使用style.xml來做到這一點,我必須在XML中多次使用它,所以我希望它作爲樣式。請參閱我的UPDATE問題!並告訴我如何修改我的style.xml請定製我的原始style.xml – MKK