简体   繁体   English

在按钮左侧的文本上对齐图标

[英]Align icon at text left in a Button

How I can align the icon at text left? 我怎样才能使图标左对齐? If I put drawableStart it appears at the center-top of the button. 如果我将drawableStart放置在按钮的中央顶部。

在此处输入图片说明

The center_vertical will align your text to center and if your drawable has invisible padding please check. center_vertical将使文本居中对齐,如果可绘制对象具有不可见的填充,请检查。 Also, check if the background resource has any padding. 另外,请检查背景资源是否有任何填充。 Otherwise below code will work fine. 否则下面的代码将正常工作。

<Button
    android:layout_width="200dp" 
    android:layout_height="80dp"
    android:drawableStart="@android:drawable/ic_dialog_info"
    android:text="@string/app_name"
    android:gravity="start|center_vertical"
    android:drawablePadding="10dp" // padding in between icon and text
    android:paddingStart="40dp" // start padding for icon
    />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM