android按钮精细文本对齐

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3632416/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 11:05:25  来源:igfitidea点击:

android button fine text alignment

androidlayoutbutton

提问by skorulis

I'm trying to create standard button in android with a background and some text in front but some fairly specific alignment. I want the text to be centered vertically and on the left with 20dp of padding. The alignment works but the padding doesn't. I know I could probably get the desired effect by putting a few spaces in the text but that seems like a hack and next I want to do a similar thing but with the text at the top so I would prefer a more elegant solution. Here's what I have:

我正在尝试在 android 中创建标准按钮,背景和前面的一些文本,但一些相当具体的对齐方式。我希望文本垂直居中并在左侧有 20dp 的填充。对齐有效,但填充无效。我知道我可以通过在文本中放置几个​​空格来获得所需的效果,但这似乎是一个黑客,接下来我想做一个类似的事情,但文本在顶部,所以我更喜欢更优雅的解决方案。这是我所拥有的:

<Button
        android:layout_width="312dp"
        android:layout_height="95dp"
        android:id="@+id/gv_music_button"
        android:text="Music"
        android:textSize="30sp"
        android:paddingLeft="20dp"
        android:gravity="left|center_vertical"
    />

采纳答案by skorulis

My mistake, padding was working correctly. Just didn't appear to be.

我的错误,填充工作正常。只是似乎没有。