【问题标题】:How to set distance betwen textview and drawable in a button?如何在按钮中设置textview和drawable之间的距离?
【发布时间】:2013-07-22 02:11:05
【问题描述】:

伙计们,我有一个按钮,如下图

我想改变文本与 drawable 之间的距离。怎么骗这个?

这是我的按钮的 xml 代码

<Button
   android:id="@+id/ButtonCancel"
   style="@style/CAGButton"
   android:drawableLeft="@drawable/selector_ic_cancel"
   android:text="@string/layer_button_cancel" />

这是 style.xml 中的 CAGButton

<style name="CAGButton" parent="@android:style/Widget.Button">
    <item name="android:drawablePadding">3dip</item>
    <item name="android:textColor">@color/cag_brown</item>
    <item name="android:layout_width">0dp</item>
    <item name="android:layout_height">wrap_content</item>
    <item name="android:layout_weight">1</item>
    <item name="android:background">@drawable/selector_button"</item>
</style>

好的,谢谢。 :)

【问题讨论】:

  • 你有解决这个问题的办法吗?
  • 嗨@gZerone 我已经发布了我的答案。你可以去看看。
  • 感谢 RR12。我得到了你的解决方案:)

标签: android xml button layout


【解决方案1】:

顺便说一句,我对按钮样式进行了一些更改,从而解决了我的问题。所以变成了这样:

    <style name="CAGButton" parent="@android:style/Widget.Button">
        <item name="android:gravity">center</item>
        <item name="android:paddingLeft">20dp</item>
        <item name="android:paddingRight">20dp</item>
        <item name="android:textColor">@color/cag_brown</item>
        <item name="android:layout_width">0dp</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_weight">1</item>
        <item name="android:background">@drawable/selector_button</item>
    </style>

我认为我们只需将填充左和/右设置为适合我们设计的最佳点。

【讨论】:

    【解决方案2】:

    这是解决方案。

                        <Button
                        android:id="@+id/xyz"
                        android:layout_width="wrap_content"
                        android:layout_height="30dp"
                        android:layout_weight="1"
                        android:background="@drawable/button_shape"
                        android:drawableLeft="@drawable/location"
                        android:drawablePadding="2dip"
                        android:gravity="center"
                        android:paddingLeft="20dip"
                        android:paddingRight="16dip"
                        android:singleLine="true"
                        android:text="XYZ"
                        android:textColor="#FFF" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-09
      • 1970-01-01
      • 1970-01-01
      • 2020-01-11
      • 2016-01-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多