android - 文本缺少最后几个像素

标签 android

我正在编写一个 Android 应用程序,有时文本的最后几个像素被截断了。它发生在应用程序各个部分的几个不同控件上。这在模拟器和我的手机上都会发生。

下面是布局的一部分,我添加了背景颜色,因此您可以看到父布局占据了整个长度,但 TextView 没有正确包装上下文 enter image description here

在底部的 'r' 之后显然是一个空隙,但顶部的 'a' 被稍微截断了。这是布局

<LinearLayout android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_gravity="center" android:background="#fbff18">

    <TextView android:id="@+id/SongRowSongName"
        android:gravity="left"
        android:layout_gravity="left"
        android:ellipsize="end"
        android:maxLines="1"
        android:singleLine="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:background="#ff1217"/>

    <TextView android:id="@+id/SongRowArtistName"
        android:gravity="left"
        android:layout_gravity="left"
        android:ellipsize="end"
        android:maxLines="1"
        android:singleLine="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:linksClickable="false"
        android:background="#ff1217" android:clickable="false"/>
</LinearLayout>

我知道我可以在 textview 上将宽度设置为 full_parent,但这只是问题的一个实例,我不明白为什么我必须这样做。 它发生的另一个主要地方是在我的 tabhost 中。 enter image description here

intent = new Intent().setClass(this, ProfileActivity.class);
spec = tabHost.newTabSpec("profile").setIndicator("Profiles",
    res.getDrawable(R.drawable.ic_tab_profile))
    .setContent(intent);
tabHost.addTab(spec);

这就是我用作背景图像选择器的内容

<?xml version="1.0" encoding="utf-8"?> 
    <selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <!-- When selected, use grey --> 
    <item android:drawable="@drawable/profile_grey" android:state_selected="true" />
    <!-- When not selected, use white--> 
    <item android:drawable="@drawable/profile_white" /> 
</selector>

我不明白为什么当父级中有足够的空间时它不能正确包装内容。

最佳答案

原来这个问题是因为我没有在 AndroidManifest 中指定 minSdkVersion。

<uses-sdk android:minSdkVersion="4"/>

如果我什么都没有,或者我的 minSdkVersion <= 3,那么就会出现问题。

干杯,

关于android - 文本缺少最后几个像素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16996519/

相关文章:

android - RxJava - 在 "subscribe"lambda 中使用不同类型的变量(多个链运算符的结果)

android - 如何在 textView 中生成数学常数 e(如 exp(1))?

android - Android DatePicker日期格式可以修改吗?

android - 使用方案打开android应用程序不起作用

android - 为什么我的进程在应用程序崩溃后仍然存在?

android - 圆形进度条内的圆形进度

android - 从 fragment 到 Activity 的交易(java类)

java - 减少 opengl es 中锯齿现象的最佳方法? (图像调整大小)

java - 如何使列表页眉和页脚不可点击?

android - 如何停止新线程(new Runnable())