3

项目清单

我想创建一个带有一个图像和超过 2 行文本的按钮。在 XML 中可能吗?(蚀)

我正在尝试使用此代码:

    android:id="@+id/itm1"
    android:text="item1"
    android:typeface="sans"
    android:textSize="20sp"
    android:textColor="#ffffff"
    android:width="250dip" 
    android:height="150dp"
    android:drawableLeft="@drawable/image1"
    android:background="@android:color/transparent" 
    android:layout_marginLeft="80dp"/>
4

2 回答 2

4

要在按钮中插入多行,您可以使用 string.xml 插入行尾。

1 在 res/values/strings.xml 中使用字符 endOfLine "\n" 创建一个新变量。例如:

<string name="multiplelines">Line1 \n Line2</string>

2 在布局文件中引用它。例如,对于一个按钮:

<Button
    android:id="@+id/start"
    android:text="@string/multiplelines"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent">
</Button>

来源:http ://www.jiahaoliuliu.com/2011/10/android-multiple-lines-for-layout.html

于 2011-10-13T18:10:38.840 回答
3

有点晚了,但您也可以在 Button 本身中指定行数:

<Button
    android:id="@+id/start"
    android:lines="2">

</Button>
于 2014-11-04T16:17:26.410 回答