Arvin ZHANG
2016-08-11 13:04Android中设置了drawableLeft的TextView文字内容显示不完整
看慕课网视屏学做Android程序,其中有一个设置了drawableLeft的TextView文字内容显示不完整。
布局代码是:
<FrameLayout
android:id="@+id/frameLayout_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="false"
android:visibility="gone">
<!-- 就是下边这个显示不全 -->
<TextView
android:id="@+id/tvDetectedInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/msg_box"
android:drawableLeft="@drawable/male"
android:drawableStart="@drawable/male"
android:gravity="center"
android:maxLines="1"
android:text="@string/default_age"
android:textColor="#ffff00ff"
android:textSize="22sp"
android:visibility="invisible"/>
</FrameLayout>
Java代码是:
//参数为:年龄,是否为男性
private Bitmap buildInfoBitmap(int age, boolean isMale) {
TextView tvAge = (TextView) mFrameLayoutContainer.findViewById(R.id.tvDetectedInfo);
tvAge.setText(age + "");
if (isMale) {
tvAge.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.male), null, null, null);
} else {
tvAge.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.female), null, null, null);
}
tvAge.setDrawingCacheEnabled(true);
Bitmap bitmap = Bitmap.createBitmap(tvAge.getDrawingCache());
tvAge.destroyDrawingCache();
return bitmap;
}
效果图:
图中的年龄只显示了一部分,实际上都是两位数的年龄。
请问这是什么原因造成的?
- 点赞
- 回答
- 收藏
- 复制链接分享
5条回答
为你推荐
- org.json.JSONException:值为10的java.lang.String类型的电子邮件无法转换为JSONObject
- android-studio
- json
- android
- php
- 1个回答
- 安卓跳转页面报错,,,
- 2个回答
- android 用selector设置edittext图片问题
- edittext
- android
- selector
- 2个回答
- Could not find a method sys_setting(View)
- android
- onclick
- 2个回答
- 在 Button 上添加 image 时,如何不使 image 紧靠在 Button 左边
- android
- 3个回答
换一换