我正在创建自定义按钮。我想设置按钮上文字的位置。按钮上的文本对齐方式
- 我有两个背景图像的按钮(button_off和button_on)第一个是正常的按钮,第二个是onFocus/onPressed状态。
- 现在我已经把按钮文字那么就应该是这样的:
,但我无法设定确切该背景按钮图像上文本的位置。 请分享你的建议来解决这个问题。
我正在创建自定义按钮。我想设置按钮上文字的位置。按钮上的文本对齐方式
,但我无法设定确切该背景按钮图像上文本的位置。 请分享你的建议来解决这个问题。
您可以尝试使用9补丁图像作为背景。有关此处的更多信息:http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch
对齐文本,使用重力选项!或填充尝试
我们可以使用填充只用于布局而不是文本。通过设置重力,我们只能设置左/右/上/下/中心对齐。但我想设置文本5像素多中心.. –
我甚至能够使用填充文本! – sat
几个方面:
android:drawableStart
LinearLayout
持有文本和图像与 背景 设置它们两个的权重为1,并将它们放入另一个LinearLayout
并使它们成为onClick
无法保证3将不经过调整或两次工作,但它值得尝试<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@android:drawable/arrow_down_float"
android:background="@drawable/btn_all_bg"
android:text="All">
Button>
您可以使用drawableLeft /右/上/下到上的按钮添加图标和文本会自动调整。
最好,最简单的方法。感谢你的回答 –
可以在XML文件中设置这些属性,`
<Button
android:id="@+id/button1"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:drawablePadding="5dp"
android:drawableLeft="@android:drawable/ic_lock_lock"
android:text="All"
android:gravity="center"/>
`
您可以使用布局按钮style="@android:style/Widget.Button"
,并且将其配置为你想要的。在XML文件中
粘贴此:
<LinearLayout
android:id="@+id/button"
style="@android:style/Widget.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:text="TextView" />
</LinearLayout>
请点击此链接[按钮](http://www.androidpeople.com/button),U将得到答案在这里。并通过这个网站冲浪你会学到很多 – Prachur
感谢它有用的链接。 –
我无法在链接页面上找到答案。此外,我认为发布链接/文章集合作为特定问题的答案是一种糟糕的风格。如果可以在文章中找到答案,至少可以直接链接到文章。 – Hinton