我正在编写一个 Android 应用程序,有时文本的最后几个像素被截断了。它发生在应用程序各个部分的几个不同控件上。这在模拟器和我的手机上都会发生。
下面是布局的一部分,我添加了背景颜色,因此您可以看到父布局占据了整个长度,但 TextView 没有正确包装上下文
在底部的 '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 中。
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/