【问题标题】:Android Eclipse how to add an image button with text [duplicate]Android Eclipse如何添加带有文本的图像按钮[重复]
【发布时间】:2013-02-05 00:59:58
【问题描述】:

可能重复:
How do I use a compound drawable instead of a LinearLayout that contains an ImageView and a TextView

我目前只有一个带有文本的按钮,但现在我想为其添加背景图像。但我不希望背景图像覆盖整个按钮。我希望它看起来像这张图片中的按钮。 (看应用截图下的图片,这是第一张图片。)这是图片的链接。

https://play.google.com/store/apps/details?id=com.pxstudios.minecraftpro&feature=related_apps#?t=W251bGwsMSwxLDEwOSwiY29tLnB4c3R1ZGlvcy5taW5lY3JhZnRwcm8iXQ..

【问题讨论】:

    标签: android


    【解决方案1】:

    您的意思是按钮右侧带有文本的列表视图?您使用两个视图,一个文本视图和一个图像视图

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal" >
        <ImageView ...>
        <TextView ...>
    </LinearLayout>
    

    【讨论】:

    • 好的。谢谢,但他们还有其他方式吗。因为我至少有 200 个按钮,这将是很多文本
    • 创建一个包含此布局的新视图子类。然后你可以通过名称声明它。虽然如果你有 200- 你可能会把它扔到 ListView 中?在这种情况下,您将在适配器的 GetView 函数中的代码中对其进行膨胀,而不是将其中的 200 个放在 xml 中。
    【解决方案2】:

    你可以这样做:

    <Button
        android:id="@+id/button_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/[your_image]"
        android:text="Your_Text"
        android:textSize="48dp" //<==give a dimension to a text
        android:textStyle="bold"//<==is better your text is bold
         />
    

    如果您使用 Eclipse,请使用图形编辑器创建您想要的按钮数量,只需复制并粘贴到您的 Xml 文件中即可。并使用 Strings.xml 来存储您的文本。

    【讨论】:

      【解决方案3】:

      您可以使用 android:drawableLeft 属性将图标设置在左侧。 Button是从TextView派生的,所以支持这个属性,

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-09-03
        • 2011-10-11
        • 1970-01-01
        • 1970-01-01
        • 2018-10-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多