Android 安卓按钮';s的文本总是省略

Android 安卓按钮';s的文本总是省略,android,button,ellipsis,Android,Button,Ellipsis,我有一个有4个按钮的布局(我正试图得到同样大小的按钮)。问题是我不希望我的第一个按钮上的文本被省略。我尝试过很多方法:将ellipsize属性设置为“none”,将singleLine属性设置为false,切断填充,但都不起作用 在eclipse图形布局中,一切看起来都很好,但当我在真实设备上尝试时,无论屏幕有多大,都会出现上述问题。 起初,我认为这是因为填充(我在.xml中为按钮定义了自定义背景,并在该形状上使用填充)。然而,移除它们并不奏效 <RelativeLayout xm

我有一个有4个按钮的布局(我正试图得到同样大小的按钮)。问题是我不希望我的第一个按钮上的文本被省略。我尝试过很多方法:将ellipsize属性设置为“none”,将singleLine属性设置为false,切断填充,但都不起作用

在eclipse图形布局中,一切看起来都很好,但当我在真实设备上尝试时,无论屏幕有多大,都会出现上述问题。 起初,我认为这是因为填充(我在.xml中为按钮定义了自定义背景,并在该形状上使用填充)。然而,移除它们并不奏效

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:gravity="center"
    android:background="@drawable/gradient_bkg"
    tools:context=".StartActivity" >

    <TableLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

    <TableRow android:layout_weight="1.0">
   <LinearLayout 
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_marginBottom="15dp"
       android:gravity="center">

        <Button
            android:id="@+id/random_words"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginRight="15dp"
            android:layout_weight="1.0"
            android:background="@drawable/button_sexy"
            android:text="Random two words"
            android:drawableLeft="@drawable/drinks"/>

        <Button
            android:id="@+id/no_data"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginLeft="15dp"
            android:layout_weight="1.0"
            android:background="@drawable/button_sexy"
            android:text="No data"
            android:drawableLeft="@drawable/body_data" />

   </LinearLayout></TableRow>

    <TableRow android:layout_weight="1">
   <LinearLayout
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_marginTop="15dp"
       android:gravity="center" >

       <Button
           android:id="@+id/result"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:layout_marginRight="15dp"
           android:layout_weight="1"
           android:background="@drawable/button_sexy"
           android:text="Result"
           android:drawableLeft="@drawable/results" />

       <Button
           android:id="@+id/reset"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:layout_marginLeft="15dp"
           android:layout_weight="1"
           android:background="@drawable/button_sexy"
           android:text="Reset"
           android:drawableLeft="@drawable/reset"/>
   </LinearLayout>
   </TableRow>
   </TableLayout>

</RelativeLayout>

我认为问题与在版面的许多级别上使用包装内容有关。我已经看到,这导致个别项目试图聪明有时和自动调整不正确或至少在一个意想不到的方式。尝试将按钮放在顶层布局上,以测试使用match_parent时是否可以获得正确的行为


但最终,使用wrap\u内容和match\u parent的组合会耗费大量时间。快速前进的方法可能是将按钮设置为固定大小,但请确保将它们设置得比您认为的大一些,以确保它可以在许多不同的屏幕大小上工作。

您的代码令人惊叹且完美。您指出的问题只会在较低的API中出现,因为您在清单中添加了一个Theme.Holo,这对于较旧的API来说很奇怪


最简单的解决方案,因为您正在使用自定义LAF:将清单中的Theme.Holo替换为Theme.Black。

能否显示布局的屏幕截图?