【问题标题】:Text on Button getting trimmed on some devices按钮上的文本在某些设备上被修剪
【发布时间】:2012-04-11 14:25:29
【问题描述】:

按钮有一个文本 "Cancel" ,在某些 Android 设备上,例如 HTC Evo (OS 2.2) ,而不是 "Cancel" ,只显示 "Ca"。

以下是放在布局xml上的按钮

<Button
            android:id="@+id/btn_upload"
            android:layout_width="150dp"
            android:layout_height="50dp"
            android:layout_alignParentTop="true"
            android:background="@drawable/btngray"
            android:shadowColor="@color/black"
            android:shadowDx="1"
            android:shadowDy="1"
            android:shadowRadius="1"
            android:text="Cancel"
            android:textColor="@color/white"
            android:textSize="16sp"
            android:textStyle="bold" >
</Button>

使用的drawable是一个九块图像,以便按钮图像根据文本调整大小。 layout:width & layout:height 是否会造成问题?

目前,无法在模拟器或我测试的设备(HTC WildFire S、LG Optimus、Samsung Galaxy 等)上复制该问题。

欢迎任何帮助/建议。

【问题讨论】:

  • 你能否给出完整的布局可能有问题可能是其他视图参数。

标签: android


【解决方案1】:

修改并添加一些属性到按钮的 xml:

android:layout_width="wrap_content"
android:singleLine="true"
android:ellipsize="none"

【讨论】:

    【解决方案2】:

    这是因为您在密度像素中给出了宽度您需要将大小指定为 wrap_content 以便按钮采用所需的确切大小 更改按钮代码如下

    <Button
                android:id="@+id/btn_upload"
                android:layout_width="wrap_content"
                android:layout_height="50dp"
                android:layout_alignParentTop="true"
                android:background="@drawable/btngray"
                android:shadowColor="@color/black"
                android:shadowDx="1"
                android:shadowDy="1"
                android:shadowRadius="1"
                android:text="Cancel"
                android:textColor="@color/white"
                android:textSize="16sp"
                android:textStyle="bold" >
    </Button>
    

    【讨论】:

      猜你喜欢
      • 2014-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-31
      • 1970-01-01
      • 2021-12-23
      相关资源
      最近更新 更多