【问题标题】:Android button with left drawable and two text lines带有左侧可绘制对象和两条文本行的 Android 按钮
【发布时间】:2011-05-05 04:21:52
【问题描述】:

如何创建一个具有左侧可绘制图标和两行文本的按钮。第一行小写,第二行大写并左对齐。 我创建了一个类似的按钮,但我无法将第二行左对齐。

按钮的布局是:

    <Button android:layout_height="wrap_content" 
            android:id="@+id/mybutton" 
            android:layout_marginTop="25dp" 
            android:drawableLeft="@drawable/myicon" 
            android:text="Button" 
            android:textColor="@color/black" 
            android:layout_width="wrap_content" 
            android:textSize="12sp">
    </Button>

我正在通过代码输入文本:

String txt = "some text<br><b>SOME TEXT</b>";
mybtn.setText(Html.fromHtml(txt));

谢谢

【问题讨论】:

    标签: android layout button


    【解决方案1】:

    尝试使用属性android:gravity="left"。默认情况下,Button 将其文本居中。

    【讨论】:

      【解决方案2】:

      @drawable 不必是图像。您可以在资源文件夹中创建 myicon.xml 并创建一个布局来保存按钮和 2 个文本视图。

      线性布局设置为水平与您的图像和嵌套线性布局设置垂直包含文本视图。

      粗略的想法在这里突出显示:http://blahti.wordpress.com/2011/03/14/build-dashboard-ui-for-android/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-12-12
        • 2017-01-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多