【问题标题】:Positioning text within button in Android在Android中的按钮内定位文本
【发布时间】:2013-12-26 18:35:09
【问题描述】:

我有一个带有箭头符号的按钮。此外,我希望按钮和相邻元素之间有一些边距:

<Button
        android:id="@+id/TSPrev"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:layout_margin="10dp"
        android:background="@android:color/holo_orange_light"
        android:text="@string/left"
        android:textSize="60sp" />

但是,当我这样做时,箭头显示如下:

当我有边距时,如何保持文本垂直居中?没有它们,按钮文本将正确显示。

谢谢

【问题讨论】:

  • 试试 android:gravity="center"
  • 箭头是背景的一部分?你也可以试试ImageButton

标签: android button margin


【解决方案1】:

也许这会对你有所帮助:

<Button
    android:id="@+id/notification"
    style="@style/Wrap"
    android:layout_margin="8dp"
    android:background="@drawable/red_shape_corner"
    android:drawableRight="@drawable/notification_bell"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:text="@string/str_notification"
    android:textColor="@android:color/white" />

你需要使用

// Nothing but Image like Arrow etc.
android:drawableRight="@drawable/notification_bell"

// Here you can put you text
android:text="@string/str_notification" 

【讨论】:

  • 所以您的建议是将箭头作为图像而不是文本?我不能很好地理解你的回答,对不起。
【解决方案2】:

尝试使用android:gravity="center"

android:gravity attribute documentation

【讨论】:

    猜你喜欢
    • 2023-03-19
    • 2013-06-21
    • 1970-01-01
    • 2021-05-21
    • 1970-01-01
    • 2012-07-05
    • 2013-05-20
    • 1970-01-01
    • 2016-10-21
    相关资源
    最近更新 更多