我试着像这样的代码如何在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